home *** CD-ROM | disk | FTP | other *** search
open in:
MacOS 8.1
|
Win98
|
DOS
browse contents |
view JSON data
|
view as text
This file was processed as: LaTeX Document
(document/latex).
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| LaTeX Document (document/latex)
| magic
| Supported |
1%
| dexvert
| MultiMate Document (document/multiMate)
| ext
| Unsupported |
1%
| dexvert
| WANG Integrated Word Processor (document/wangIWP)
| ext
| Unsupported |
1%
| dexvert
| Excellence! Document (document/excellenceDocument)
| ext
| Unsupported |
1%
| dexvert
| IBM DisplayWrite Document (document/ibmDisplayWriteDocument)
| ext
| Unsupported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| LaTeX document text
| default
| |
99%
| file
| LaTeX document, ASCII text
| default
| |
100%
| checkBytes
| Printable ASCII
| default
| |
100%
| perlTextCheck
| Likely Text (Perl)
| default
| |
100%
| detectItEasy
| Format: plain text[LF]
| default (weak)
|
|
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 63 68 61 70 74 65 72 | 7b 46 6f 72 65 69 67 6e |\chapter|{Foreign|
|00000010| 20 4c 61 6e 67 75 61 67 | 65 20 49 6e 74 65 72 66 | Languag|e Interf|
|00000020| 61 63 65 7d 09 09 5c 6c | 61 62 65 6c 7b 73 65 63 |ace}..\l|abel{sec|
|00000030| 3a 66 6f 72 65 69 67 6e | 7d 0a 0a 5c 6e 65 77 6c |:foreign|}..\newl|
|00000040| 65 6e 67 74 68 7b 5c 74 | 61 62 6c 65 66 74 7d 0a |ength{\t|ableft}.|
|00000050| 5c 73 65 74 74 6f 77 69 | 64 74 68 7b 5c 74 61 62 |\settowi|dth{\tab|
|00000060| 6c 65 66 74 7d 7b 5c 63 | 6f 6e 73 74 7b 50 4c 5f |left}{\c|onst{PL_|
|00000070| 51 55 45 52 59 5f 4f 52 | 47 53 59 4d 42 4f 4c 46 |QUERY_OR|GSYMBOLF|
|00000080| 49 4c 45 7d 7d 0a 0a 53 | 57 49 2d 50 72 6f 6c 6f |ILE}}..S|WI-Prolo|
|00000090| 67 20 6f 66 66 65 72 73 | 20 61 20 70 6f 77 65 72 |g offers| a power|
|000000a0| 66 75 6c 20 69 6e 74 65 | 72 66 61 63 65 20 74 6f |ful inte|rface to|
|000000b0| 20 43 20 5c 63 69 74 65 | 7b 4b 65 72 6e 69 67 68 | C \cite|{Kernigh|
|000000c0| 61 6e 3a 37 38 7d 2e 20 | 54 68 65 0a 6d 61 69 6e |an:78}. |The.main|
|000000d0| 20 64 65 73 69 67 6e 20 | 6f 62 6a 65 63 74 69 76 | design |objectiv|
|000000e0| 65 73 20 6f 66 20 74 68 | 65 20 66 6f 72 65 69 67 |es of th|e foreig|
|000000f0| 6e 20 6c 61 6e 67 75 61 | 67 65 20 69 6e 74 65 72 |n langua|ge inter|
|00000100| 66 61 63 65 20 61 72 65 | 20 66 6c 65 78 69 62 69 |face are| flexibi|
|00000110| 6c 69 74 79 0a 61 6e 64 | 20 70 65 72 66 6f 72 6d |lity.and| perform|
|00000120| 61 6e 63 65 2e 20 41 20 | 66 6f 72 65 69 67 6e 20 |ance. A |foreign |
|00000130| 70 72 65 64 69 63 61 74 | 65 20 69 73 20 61 20 43 |predicat|e is a C|
|00000140| 2d 66 75 6e 63 74 69 6f | 6e 20 74 68 61 74 20 68 |-functio|n that h|
|00000150| 61 73 20 74 68 65 20 73 | 61 6d 65 0a 6e 75 6d 62 |as the s|ame.numb|
|00000160| 65 72 20 6f 66 20 61 72 | 67 75 6d 65 6e 74 73 20 |er of ar|guments |
|00000170| 61 73 20 74 68 65 20 70 | 72 65 64 69 63 61 74 65 |as the p|redicate|
|00000180| 20 72 65 70 72 65 73 65 | 6e 74 65 64 2e 20 43 2d | represe|nted. C-|
|00000190| 66 75 6e 63 74 69 6f 6e | 73 20 61 72 65 0a 70 72 |function|s are.pr|
|000001a0| 6f 76 69 64 65 64 20 74 | 6f 20 61 6e 61 6c 79 73 |ovided t|o analys|
|000001b0| 65 20 74 68 65 20 70 61 | 73 73 65 64 20 74 65 72 |e the pa|ssed ter|
|000001c0| 6d 73 2c 20 63 6f 6e 76 | 65 72 74 20 74 68 65 6d |ms, conv|ert them|
|000001d0| 20 74 6f 20 62 61 73 69 | 63 20 43 2d 74 79 70 65 | to basi|c C-type|
|000001e0| 73 20 61 73 0a 77 65 6c | 6c 20 61 73 20 74 6f 20 |s as.wel|l as to |
|000001f0| 69 6e 73 74 61 6e 74 69 | 61 74 65 20 61 72 67 75 |instanti|ate argu|
|00000200| 6d 65 6e 74 73 20 75 73 | 69 6e 67 20 75 6e 69 66 |ments us|ing unif|
|00000210| 69 63 61 74 69 6f 6e 2e | 20 4e 6f 6e 2d 64 65 74 |ication.| Non-det|
|00000220| 65 72 6d 69 6e 69 73 74 | 69 63 0a 66 6f 72 65 69 |erminist|ic.forei|
|00000230| 67 6e 20 70 72 65 64 69 | 63 61 74 65 73 20 61 72 |gn predi|cates ar|
|00000240| 65 20 73 75 70 70 6f 72 | 74 65 64 2c 20 70 72 6f |e suppor|ted, pro|
|00000250| 76 69 64 69 6e 67 20 74 | 68 65 20 66 6f 72 65 69 |viding t|he forei|
|00000260| 67 6e 20 66 75 6e 63 74 | 69 6f 6e 20 77 69 74 68 |gn funct|ion with|
|00000270| 20 61 0a 68 61 6e 64 6c | 65 20 74 6f 20 63 6f 6e | a.handl|e to con|
|00000280| 74 72 6f 6c 20 62 61 63 | 6b 74 72 61 63 6b 69 6e |trol bac|ktrackin|
|00000290| 67 2e 0a 0a 43 20 63 61 | 6e 20 63 61 6c 6c 20 50 |g...C ca|n call P|
|000002a0| 72 6f 6c 6f 67 20 70 72 | 65 64 69 63 61 74 65 73 |rolog pr|edicates|
|000002b0| 2c 20 70 72 6f 76 69 64 | 69 6e 67 20 62 6f 74 68 |, provid|ing both|
|000002c0| 20 61 6e 20 71 75 65 72 | 79 20 69 6e 74 65 72 66 | an quer|y interf|
|000002d0| 61 63 65 20 61 6e 64 0a | 61 6e 20 69 6e 74 65 72 |ace and.|an inter|
|000002e0| 66 61 63 65 20 74 6f 20 | 65 78 74 72 61 63 74 20 |face to |extract |
|000002f0| 6d 75 6c 74 69 70 6c 65 | 20 73 6f 6c 75 74 69 6f |multiple| solutio|
|00000300| 6e 73 20 66 72 6f 6d 20 | 61 6e 20 6e 6f 6e 2d 64 |ns from |an non-d|
|00000310| 65 74 65 72 6d 69 6e 69 | 73 74 69 63 0a 50 72 6f |etermini|stic.Pro|
|00000320| 6c 6f 67 20 70 72 65 64 | 69 63 61 74 65 2e 20 20 |log pred|icate. |
|00000330| 54 68 65 72 65 20 69 73 | 20 6e 6f 20 6c 69 6d 69 |There is| no limi|
|00000340| 74 20 74 6f 20 74 68 65 | 20 6e 65 73 74 69 6e 67 |t to the| nesting|
|00000350| 20 6f 66 20 50 72 6f 6c | 6f 67 20 63 61 6c 6c 69 | of Prol|og calli|
|00000360| 6e 67 0a 43 2c 20 63 61 | 6c 6c 69 6e 67 20 50 72 |ng.C, ca|lling Pr|
|00000370| 6f 6c 6f 67 2c 20 65 74 | 63 2e 20 20 49 74 20 69 |olog, et|c. It i|
|00000380| 73 20 61 6c 73 6f 20 70 | 6f 73 73 69 62 6c 65 20 |s also p|ossible |
|00000390| 74 6f 20 77 72 69 74 65 | 20 74 68 65 20 60 6d 61 |to write| the `ma|
|000003a0| 69 6e 27 20 69 6e 0a 43 | 20 61 6e 64 20 75 73 65 |in' in.C| and use|
|000003b0| 20 50 72 6f 6c 6f 67 20 | 61 73 20 61 6e 20 65 6d | Prolog |as an em|
|000003c0| 62 65 64 64 65 64 20 6c | 6f 67 69 63 61 6c 20 65 |bedded l|ogical e|
|000003d0| 6e 67 69 6e 65 2e 0a 0a | 0a 5c 73 65 63 74 69 6f |ngine...|.\sectio|
|000003e0| 6e 7b 4f 76 65 72 76 69 | 65 77 20 6f 66 20 74 68 |n{Overvi|ew of th|
|000003f0| 65 20 49 6e 74 65 72 66 | 61 63 65 7d 0a 0a 41 20 |e Interf|ace}..A |
|00000400| 73 70 65 63 69 61 6c 20 | 69 6e 63 6c 75 64 65 20 |special |include |
|00000410| 66 69 6c 65 20 63 61 6c | 6c 65 64 20 5c 66 69 6c |file cal|led \fil|
|00000420| 65 7b 53 57 49 2d 50 72 | 6f 6c 6f 67 2e 68 7d 20 |e{SWI-Pr|olog.h} |
|00000430| 73 68 6f 75 6c 64 20 62 | 65 20 69 6e 63 6c 75 64 |should b|e includ|
|00000440| 65 64 20 77 69 74 68 0a | 65 61 63 68 20 43 2d 73 |ed with.|each C-s|
|00000450| 6f 75 72 63 65 20 66 69 | 6c 65 20 74 68 61 74 20 |ource fi|le that |
|00000460| 69 73 20 74 6f 20 62 65 | 20 6c 6f 61 64 65 64 20 |is to be| loaded |
|00000470| 76 69 61 20 74 68 65 20 | 66 6f 72 65 69 67 6e 20 |via the |foreign |
|00000480| 69 6e 74 65 72 66 61 63 | 65 2e 20 20 54 68 65 0a |interfac|e. The.|
|00000490| 69 6e 73 74 61 6c 6c 61 | 74 69 6f 6e 20 70 72 6f |installa|tion pro|
|000004a0| 63 65 73 73 20 69 6e 73 | 74 61 6c 6c 73 20 74 68 |cess ins|talls th|
|000004b0| 69 73 20 66 69 6c 65 20 | 69 6e 20 74 68 65 20 64 |is file |in the d|
|000004c0| 69 72 65 63 74 6f 72 79 | 20 5c 66 69 6c 65 7b 69 |irectory| \file{i|
|000004d0| 6e 63 6c 75 64 65 7d 0a | 69 6e 20 74 68 65 20 53 |nclude}.|in the S|
|000004e0| 57 49 2d 50 72 6f 6c 6f | 67 20 68 6f 6d 65 20 64 |WI-Prolo|g home d|
|000004f0| 69 72 65 63 74 6f 72 79 | 20 28 5c 65 78 61 6d 7b |irectory| (\exam{|
|00000500| 3f 2d 20 66 65 61 74 75 | 72 65 28 68 6f 6d 65 2c |?- featu|re(home,|
|00000510| 20 48 6f 6d 65 29 2e 7d | 29 2e 20 20 54 68 69 73 | Home).}|). This|
|00000520| 0a 43 2d 68 65 61 64 65 | 72 20 66 69 6c 65 20 64 |.C-heade|r file d|
|00000530| 65 66 69 6e 65 73 20 76 | 61 72 69 6f 75 73 20 64 |efines v|arious d|
|00000540| 61 74 61 20 74 79 70 65 | 73 2c 20 6d 61 63 72 6f |ata type|s, macro|
|00000550| 73 20 61 6e 64 20 66 75 | 6e 63 74 69 6f 6e 73 20 |s and fu|nctions |
|00000560| 74 68 61 74 20 63 61 6e | 0a 62 65 20 75 73 65 64 |that can|.be used|
|00000570| 20 74 6f 20 63 6f 6d 6d | 75 6e 69 63 61 74 65 20 | to comm|unicate |
|00000580| 77 69 74 68 20 53 57 49 | 2d 50 72 6f 6c 6f 67 2e |with SWI|-Prolog.|
|00000590| 20 20 46 75 6e 63 74 69 | 6f 6e 73 20 61 6e 64 20 | Functi|ons and |
|000005a0| 6d 61 63 72 6f 73 20 63 | 61 6e 20 62 65 0a 64 69 |macros c|an be.di|
|000005b0| 76 69 64 65 64 20 69 6e | 74 6f 20 74 68 65 20 66 |vided in|to the f|
|000005c0| 6f 6c 6c 6f 77 69 6e 67 | 20 63 61 74 65 67 6f 72 |ollowing| categor|
|000005d0| 69 65 73 3a 0a 0a 5c 62 | 65 67 69 6e 7b 73 68 6f |ies:..\b|egin{sho|
|000005e0| 72 74 6c 69 73 74 7d 0a | 20 20 20 20 5c 69 74 65 |rtlist}.| \ite|
|000005f0| 6d 20 41 6e 61 6c 79 73 | 69 6e 67 20 50 72 6f 6c |m Analys|ing Prol|
|00000600| 6f 67 20 74 65 72 6d 73 | 0a 20 20 20 20 5c 69 74 |og terms|. \it|
|00000610| 65 6d 20 43 6f 6e 73 74 | 72 75 63 74 69 6e 67 20 |em Const|ructing |
|00000620| 6e 65 77 20 74 65 72 6d | 73 0a 20 20 20 20 5c 69 |new term|s. \i|
|00000630| 74 65 6d 20 55 6e 69 66 | 79 69 6e 67 20 74 65 72 |tem Unif|ying ter|
|00000640| 6d 73 0a 20 20 20 20 5c | 69 74 65 6d 20 52 65 74 |ms. \|item Ret|
|00000650| 75 72 6e 69 6e 67 20 63 | 6f 6e 74 72 6f 6c 20 69 |urning c|ontrol i|
|00000660| 6e 66 6f 72 6d 61 74 69 | 6f 6e 20 74 6f 20 50 72 |nformati|on to Pr|
|00000670| 6f 6c 6f 67 0a 20 20 20 | 20 5c 69 74 65 6d 20 52 |olog. | \item R|
|00000680| 65 67 69 73 74 65 72 69 | 6e 67 20 66 6f 72 65 69 |egisteri|ng forei|
|00000690| 67 6e 20 70 72 65 64 69 | 63 61 74 65 73 20 77 69 |gn predi|cates wi|
|000006a0| 74 68 20 50 72 6f 6c 6f | 67 0a 20 20 20 20 5c 69 |th Prolo|g. \i|
|000006b0| 74 65 6d 20 43 61 6c 6c | 69 6e 67 20 50 72 6f 6c |tem Call|ing Prol|
|000006c0| 6f 67 20 66 72 6f 6d 20 | 43 0a 20 20 20 20 5c 69 |og from |C. \i|
|000006d0| 74 65 6d 20 47 6c 6f 62 | 61 6c 20 61 63 74 69 6f |tem Glob|al actio|
|000006e0| 6e 73 20 6f 6e 20 50 72 | 6f 6c 6f 67 20 28 68 61 |ns on Pr|olog (ha|
|000006f0| 6c 74 2c 20 62 72 65 61 | 6b 2c 20 61 62 6f 72 74 |lt, brea|k, abort|
|00000700| 2c 20 65 74 63 2e 29 0a | 5c 65 6e 64 7b 73 68 6f |, etc.).|\end{sho|
|00000710| 72 74 6c 69 73 74 7d 0a | 0a 0a 5c 73 65 63 74 69 |rtlist}.|..\secti|
|00000720| 6f 6e 7b 4c 69 6e 6b 69 | 6e 67 20 46 6f 72 65 69 |on{Linki|ng Forei|
|00000730| 67 6e 20 4d 6f 64 75 6c | 65 73 7d 0a 0a 46 6f 72 |gn Modul|es}..For|
|00000740| 65 69 67 6e 20 6d 6f 64 | 75 6c 65 73 20 6d 61 79 |eign mod|ules may|
|00000750| 20 62 65 20 6c 69 6e 6b | 65 64 20 74 6f 20 50 72 | be link|ed to Pr|
|00000760| 6f 6c 6f 67 20 69 6e 20 | 74 68 72 65 65 20 77 61 |olog in |three wa|
|00000770| 79 73 2e 20 55 73 69 6e | 67 20 0a 5c 6a 61 72 67 |ys. Usin|g .\jarg|
|00000780| 6f 6e 7b 73 74 61 74 69 | 63 20 6c 69 6e 6b 69 6e |on{stati|c linkin|
|00000790| 67 7d 2c 20 74 68 65 20 | 65 78 74 65 6e 73 69 6f |g}, the |extensio|
|000007a0| 6e 73 2c 20 61 20 73 6d | 61 6c 6c 20 64 65 73 63 |ns, a sm|all desc|
|000007b0| 72 69 70 74 69 6f 6e 20 | 66 69 6c 65 20 61 6e 64 |ription |file and|
|000007c0| 20 74 68 65 20 62 61 73 | 69 63 0a 53 57 49 2d 50 | the bas|ic.SWI-P|
|000007d0| 72 6f 6c 6f 67 20 6f 62 | 6a 65 63 74 20 66 69 6c |rolog ob|ject fil|
|000007e0| 65 20 61 72 65 20 6c 69 | 6e 6b 65 64 20 74 6f 67 |e are li|nked tog|
|000007f0| 65 74 68 65 72 20 74 6f | 20 66 6f 72 6d 20 61 20 |ether to| form a |
|00000800| 6e 65 77 20 65 78 65 63 | 75 74 61 62 6c 65 2e 0a |new exec|utable..|
|00000810| 55 73 69 6e 67 20 5c 6a | 61 72 67 6f 6e 7b 64 79 |Using \j|argon{dy|
|00000820| 6e 61 6d 69 63 20 6c 69 | 6e 6b 69 6e 67 7d 2c 20 |namic li|nking}, |
|00000830| 74 68 65 20 65 78 74 65 | 6e 73 69 6f 6e 73 20 61 |the exte|nsions a|
|00000840| 72 65 20 6c 69 6e 6b 65 | 64 20 74 6f 20 61 20 73 |re linke|d to a s|
|00000850| 68 61 72 65 64 0a 6c 69 | 62 72 61 72 79 20 28 5c |hared.li|brary (\|
|00000860| 66 69 6c 65 65 78 74 7b | 73 6f 7d 20 66 69 6c 65 |fileext{|so} file|
|00000870| 20 6f 6e 20 6d 6f 73 74 | 20 55 6e 69 78 20 73 79 | on most| Unix sy|
|00000880| 73 74 65 6d 73 29 20 6f | 72 20 64 79 6e 61 6d 69 |stems) o|r dynami|
|00000890| 63 2d 6c 69 6e 6b 20 6c | 69 62 72 61 72 79 0a 28 |c-link l|ibrary.(|
|000008a0| 5c 66 69 6c 65 65 78 74 | 7b 44 4c 4c 7d 20 66 69 |\fileext|{DLL} fi|
|000008b0| 6c 65 20 6f 6e 20 4d 69 | 63 72 6f 73 6f 66 74 20 |le on Mi|crosoft |
|000008c0| 70 6c 61 74 66 6f 72 6d | 73 29 20 61 6e 64 20 6c |platform|s) and l|
|000008d0| 6f 61 64 65 64 20 69 6e | 74 6f 20 74 68 65 20 74 |oaded in|to the t|
|000008e0| 68 65 20 72 75 6e 6e 69 | 6e 67 0a 50 72 6f 6c 6f |he runni|ng.Prolo|
|000008f0| 67 20 70 72 6f 63 65 73 | 73 2e 25 0a 20 20 20 20 |g proces|s.%. |
|00000900| 5c 66 6f 6f 74 6e 6f 74 | 65 7b 54 68 65 20 73 79 |\footnot|e{The sy|
|00000910| 73 74 65 6d 20 61 6c 73 | 6f 20 63 6f 6e 74 61 69 |stem als|o contai|
|00000920| 6e 73 20 63 6f 64 65 20 | 74 6f 20 6c 6f 61 64 20 |ns code |to load |
|00000930| 5c 66 69 6c 65 65 78 74 | 7b 6f 7d 20 66 69 6c 65 |\fileext|{o} file|
|00000940| 73 0a 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |s. | |
|00000950| 64 69 72 65 63 74 6c 79 | 20 66 6f 72 20 73 6f 6d |directly| for som|
|00000960| 65 20 6f 70 65 72 61 74 | 69 6e 67 20 73 79 73 74 |e operat|ing syst|
|00000970| 65 6d 73 2c 20 6e 6f 74 | 61 62 6c 79 20 55 6e 69 |ems, not|ably Uni|
|00000980| 78 20 73 79 73 74 65 6d | 73 0a 20 20 20 20 20 20 |x system|s. |
|00000990| 20 20 20 20 20 20 20 20 | 75 73 69 6e 67 20 74 68 | |using th|
|000009a0| 65 20 42 53 44 20 5c 66 | 69 6c 65 7b 61 2e 6f 75 |e BSD \f|ile{a.ou|
|000009b0| 74 7d 20 65 78 65 63 75 | 74 61 62 6c 65 20 66 6f |t} execu|table fo|
|000009c0| 72 6d 61 74 2e 20 41 73 | 20 74 68 65 20 6e 75 6d |rmat. As| the num|
|000009d0| 62 65 72 20 6f 66 0a 20 | 20 20 20 20 20 20 20 20 |ber of. | |
|000009e0| 20 20 20 20 20 55 6e 69 | 78 20 70 6c 61 74 66 6f | Uni|x platfo|
|000009f0| 72 6d 73 20 73 75 70 70 | 6f 72 74 69 6e 67 20 74 |rms supp|orting t|
|00000a00| 68 69 73 20 67 65 74 73 | 20 71 75 69 63 6b 6c 79 |his gets| quickly|
|00000a10| 20 73 6d 61 6c 6c 65 72 | 20 61 6e 64 0a 20 20 20 | smaller| and. |
|00000a20| 20 20 20 20 20 20 20 20 | 20 20 20 74 68 69 73 20 | | this |
|00000a30| 69 6e 74 65 72 66 61 63 | 65 20 69 73 20 64 69 66 |interfac|e is dif|
|00000a40| 66 69 63 75 6c 74 20 74 | 6f 20 70 6f 72 74 20 61 |ficult t|o port a|
|00000a50| 6e 64 20 73 6c 6f 77 2c | 20 69 74 20 69 73 20 6e |nd slow,| it is n|
|00000a60| 6f 0a 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |o. | |
|00000a70| 6c 6f 6e 67 65 72 20 64 | 65 73 63 72 69 62 65 64 |longer d|escribed|
|00000a80| 20 69 6e 20 74 68 69 73 | 20 6d 61 6e 75 61 6c 2e | in this| manual.|
|00000a90| 20 20 54 68 65 20 62 65 | 73 74 20 61 6c 74 65 72 | The be|st alter|
|00000aa0| 6e 61 74 69 76 65 6c 79 | 0a 20 20 20 20 20 20 20 |natively|. |
|00000ab0| 20 20 20 20 20 20 20 77 | 6f 75 6c 64 20 62 65 20 | w|ould be |
|00000ac0| 74 6f 20 75 73 65 20 74 | 68 65 20 5c 69 64 78 7b |to use t|he \idx{|
|00000ad0| 64 6c 64 7d 20 70 61 63 | 6b 61 67 65 20 6f 6e 20 |dld} pac|kage on |
|00000ae0| 6d 61 63 68 69 6e 65 73 | 20 64 6f 0a 09 20 20 20 |machines| do.. |
|00000af0| 20 20 20 6e 6f 74 20 68 | 61 76 65 20 73 68 61 72 | not h|ave shar|
|00000b00| 65 64 20 6c 69 62 72 61 | 72 69 65 73 7d 2e 0a 0a |ed libra|ries}...|
|00000b10| 5c 73 75 62 73 65 63 74 | 69 6f 6e 7b 57 68 61 74 |\subsect|ion{What|
|00000b20| 20 6c 69 6e 6b 69 6e 67 | 20 69 73 20 70 72 6f 76 | linking| is prov|
|00000b30| 69 64 65 64 3f 7d 0a 0a | 54 68 65 20 5c 6a 61 72 |ided?}..|The \jar|
|00000b40| 67 6f 6e 7b 73 74 61 74 | 69 63 20 6c 69 6e 6b 69 |gon{stat|ic linki|
|00000b50| 6e 67 7d 20 73 63 68 65 | 6d 61 20 63 61 6e 20 62 |ng} sche|ma can b|
|00000b60| 65 20 75 73 65 64 20 6f | 6e 20 61 6c 6c 20 76 65 |e used o|n all ve|
|00000b70| 72 73 69 6f 6e 73 20 6f | 66 0a 53 57 49 2d 50 72 |rsions o|f.SWI-Pr|
|00000b80| 6f 6c 6f 67 2e 20 20 54 | 68 65 20 66 65 61 74 75 |olog. T|he featu|
|00000b90| 72 65 2f 32 20 70 72 65 | 64 69 63 61 74 65 20 6d |re/2 pre|dicate m|
|00000ba0| 61 79 20 62 65 20 75 73 | 65 64 20 74 6f 20 66 69 |ay be us|ed to fi|
|00000bb0| 6e 64 20 6f 75 74 20 77 | 68 61 74 0a 6f 74 68 65 |nd out w|hat.othe|
|00000bc0| 72 20 6c 69 6e 6b 69 6e | 67 20 6d 65 74 68 6f 64 |r linkin|g method|
|00000bd0| 73 20 61 72 65 20 70 72 | 6f 76 69 64 65 64 20 66 |s are pr|ovided f|
|00000be0| 6f 72 20 74 68 69 73 20 | 76 65 72 73 69 6f 6e 2e |or this |version.|
|00000bf0| 0a 0a 5c 62 65 67 69 6e | 7b 69 74 65 6d 6c 69 73 |..\begin|{itemlis|
|00000c00| 74 7d 0a 20 20 20 20 5c | 69 74 65 6d 20 5b 66 65 |t}. \|item [fe|
|00000c10| 61 74 75 72 65 28 6f 70 | 65 6e 5f 73 68 61 72 65 |ature(op|en_share|
|00000c20| 64 5f 6f 62 6a 65 63 74 | 2c 20 74 72 75 65 29 5d |d_object|, true)]|
|00000c30| 0a 5c 69 6e 64 65 78 7b | 64 6c 6f 70 65 6e 7d 5c |.\index{|dlopen}\|
|00000c40| 69 6e 64 65 78 7b 2e 73 | 6f 20 66 69 6c 65 73 7d |index{.s|o files}|
|00000c50| 25 0a 49 66 20 74 68 69 | 73 20 73 75 63 63 65 65 |%.If thi|s succee|
|00000c60| 64 73 20 74 68 65 20 73 | 79 73 74 65 6d 20 70 72 |ds the s|ystem pr|
|00000c70| 6f 76 69 64 65 73 20 74 | 68 65 20 6f 70 65 6e 5f |ovides t|he open_|
|00000c80| 73 68 61 72 65 64 5f 6f | 62 6a 65 63 74 2f 32 20 |shared_o|bject/2 |
|00000c90| 61 6e 64 0a 72 65 6c 61 | 74 65 64 20 70 72 65 64 |and.rela|ted pred|
|00000ca0| 69 63 61 74 65 73 20 74 | 68 61 74 20 61 6c 6c 6f |icates t|hat allo|
|00000cb0| 77 20 66 6f 72 20 68 61 | 6e 64 6c 69 6e 67 20 55 |w for ha|ndling U|
|00000cc0| 6e 69 78 20 73 68 61 72 | 65 64 20 6f 62 6a 65 63 |nix shar|ed objec|
|00000cd0| 74 20 66 69 6c 65 73 0a | 62 61 73 65 64 20 6f 6e |t files.|based on|
|00000ce0| 20 74 68 65 20 55 6e 69 | 78 20 6c 69 62 72 61 72 | the Uni|x librar|
|00000cf0| 79 20 66 75 6e 63 74 69 | 6f 6e 73 20 5c 6d 61 6e |y functi|ons \man|
|00000d00| 72 65 66 7b 64 6c 6f 70 | 65 6e 7d 7b 32 7d 20 61 |ref{dlop|en}{2} a|
|00000d10| 6e 64 20 66 72 69 65 6e | 64 73 2e 20 53 65 65 0a |nd frien|ds. See.|
|00000d20| 5c 73 65 63 72 65 66 7b | 73 68 6c 69 62 7d 2e 0a |\secref{|shlib}..|
|00000d30| 20 20 20 20 5c 69 74 65 | 6d 20 5b 66 65 61 74 75 | \ite|m [featu|
|00000d40| 72 65 28 64 6c 6c 2c 20 | 74 72 75 65 29 5d 0a 49 |re(dll, |true)].I|
|00000d50| 66 20 74 68 69 73 20 73 | 75 63 63 65 65 64 73 20 |f this s|ucceeds |
|00000d60| 74 68 65 20 73 79 73 74 | 65 6d 20 70 72 6f 76 69 |the syst|em provi|
|00000d70| 64 65 73 20 61 6e 20 69 | 6e 74 65 72 66 61 63 65 |des an i|nterface|
|00000d80| 20 66 6f 72 20 6c 6f 61 | 64 69 6e 67 20 5c 66 69 | for loa|ding \fi|
|00000d90| 6c 65 65 78 74 7b 44 4c | 4c 7d 0a 66 69 6c 65 73 |leext{DL|L}.files|
|00000da0| 20 62 79 20 6d 65 61 6e | 73 20 6f 66 20 6f 70 65 | by mean|s of ope|
|00000db0| 6e 5f 64 6c 6c 2f 32 20 | 61 6e 64 20 66 72 69 65 |n_dll/2 |and frie|
|00000dc0| 6e 64 73 2e 20 53 65 65 | 20 5c 73 65 63 72 65 66 |nds. See| \secref|
|00000dd0| 7b 73 68 6c 69 62 7d 2e | 0a 5c 65 6e 64 7b 69 74 |{shlib}.|.\end{it|
|00000de0| 65 6d 6c 69 73 74 7d 0a | 0a 49 66 20 65 69 74 68 |emlist}.|.If eith|
|00000df0| 65 72 20 74 68 65 20 66 | 65 61 74 75 72 65 20 5c |er the f|eature \|
|00000e00| 63 6f 6e 73 74 7b 6f 70 | 65 6e 5f 73 68 61 72 65 |const{op|en_share|
|00000e10| 64 5f 6f 62 6a 65 63 74 | 7d 20 6f 72 20 5c 63 6f |d_object|} or \co|
|00000e20| 6e 73 74 7b 64 6c 6c 7d | 20 69 73 20 74 72 75 65 |nst{dll}| is true|
|00000e30| 2c 20 74 68 65 0a 6c 69 | 62 72 61 72 79 20 5c 66 |, the.li|brary \f|
|00000e40| 69 6c 65 7b 6c 69 62 72 | 61 72 79 28 73 68 6c 69 |ile{libr|ary(shli|
|00000e50| 62 29 7d 20 70 72 6f 76 | 69 64 65 73 20 61 20 63 |b)} prov|ides a c|
|00000e60| 6f 6d 6d 6f 6e 20 69 6e | 74 65 72 66 61 63 65 20 |ommon in|terface |
|00000e70| 66 6f 72 20 6c 6f 61 64 | 69 6e 67 0a 66 6f 72 65 |for load|ing.fore|
|00000e80| 69 67 6e 20 66 69 6c 65 | 73 20 66 72 6f 6d 20 50 |ign file|s from P|
|00000e90| 72 6f 6c 6f 67 2e 0a 0a | 0a 5c 73 75 62 73 65 63 |rolog...|.\subsec|
|00000ea0| 74 69 6f 6e 7b 57 68 61 | 74 20 6b 69 6e 64 20 6f |tion{Wha|t kind o|
|00000eb0| 66 20 6c 6f 61 64 69 6e | 67 20 73 68 6f 75 6c 64 |f loadin|g should|
|00000ec0| 20 49 20 62 65 20 75 73 | 69 6e 67 3f 7d 0a 0a 41 | I be us|ing?}..A|
|00000ed0| 6c 6c 20 64 65 73 63 72 | 69 62 65 64 20 61 70 70 |ll descr|ibed app|
|00000ee0| 72 6f 61 63 68 65 73 20 | 68 61 76 65 20 74 68 65 |roaches |have the|
|00000ef0| 69 72 20 61 64 76 61 6e | 74 61 67 65 73 20 61 6e |ir advan|tages an|
|00000f00| 64 20 64 69 73 61 64 76 | 61 6e 74 61 67 65 73 2e |d disadv|antages.|
|00000f10| 20 53 74 61 74 69 63 0a | 6c 69 6e 6b 69 6e 67 20 | Static.|linking |
|00000f20| 69 73 20 70 6f 72 74 61 | 62 6c 65 20 61 6e 64 20 |is porta|ble and |
|00000f30| 61 6c 6c 6f 77 73 20 66 | 6f 72 20 64 65 62 75 67 |allows f|or debug|
|00000f40| 67 69 6e 67 20 6f 6e 20 | 61 6c 6c 20 70 6c 61 74 |ging on |all plat|
|00000f50| 66 6f 72 6d 73 2e 20 49 | 74 20 69 73 0a 72 65 6c |forms. I|t is.rel|
|00000f60| 61 74 69 76 65 6c 79 20 | 63 75 6d 62 65 72 73 6f |atively |cumberso|
|00000f70| 6d 65 20 61 6e 64 20 74 | 68 65 20 6c 69 62 72 61 |me and t|he libra|
|00000f80| 72 69 65 73 20 79 6f 75 | 20 6e 65 65 64 20 74 6f |ries you| need to|
|00000f90| 20 70 61 73 73 20 74 6f | 20 74 68 65 20 6c 69 6e | pass to| the lin|
|00000fa0| 6b 65 72 0a 6d 61 79 20 | 76 61 72 79 20 66 72 6f |ker.may |vary fro|
|00000fb0| 6d 20 73 79 73 74 65 6d | 20 74 6f 20 73 79 73 74 |m system| to syst|
|00000fc0| 65 6d 2e 0a 0a 4c 6f 61 | 64 69 6e 67 20 73 68 61 |em...Loa|ding sha|
|00000fd0| 72 65 64 20 6f 62 6a 65 | 63 74 73 20 6f 72 20 44 |red obje|cts or D|
|00000fe0| 4c 4c 20 66 69 6c 65 73 | 20 70 72 6f 76 69 64 65 |LL files| provide|
|00000ff0| 73 20 73 68 61 72 69 6e | 67 20 61 6e 64 20 70 72 |s sharin|g and pr|
|00001000| 6f 74 65 63 74 69 6f 6e | 20 61 6e 64 0a 69 73 20 |otection| and.is |
|00001010| 67 65 6e 65 72 61 6c 6c | 79 20 74 68 65 20 62 65 |generall|y the be|
|00001020| 73 74 20 63 68 6f 69 63 | 65 2e 20 54 68 65 20 6f |st choic|e. The o|
|00001030| 6c 64 20 28 61 6e 64 20 | 61 6c 73 6f 20 62 61 64 |ld (and |also bad|
|00001040| 6c 79 20 70 6f 72 74 61 | 62 6c 65 29 0a 73 61 76 |ly porta|ble).sav|
|00001050| 65 2f 5b 31 2c 32 5d 20 | 61 6e 64 20 73 61 76 65 |e/[1,2] |and save|
|00001060| 5f 70 72 6f 67 72 61 6d | 2f 5b 31 2c 32 5d 20 64 |_program|/[1,2] d|
|00001070| 6f 20 6e 6f 74 20 63 6f | 6f 70 65 72 61 74 65 20 |o not co|operate |
|00001080| 77 69 74 68 20 74 68 69 | 73 20 6d 65 63 68 61 6e |with thi|s mechan|
|00001090| 69 73 6d 2c 0a 62 75 74 | 20 74 68 65 20 6d 6f 72 |ism,.but| the mor|
|000010a0| 65 20 72 65 63 65 6e 74 | 20 71 73 61 76 65 5f 70 |e recent| qsave_p|
|000010b0| 72 6f 67 72 61 6d 2f 5b | 31 2c 32 5d 20 63 61 6e |rogram/[|1,2] can|
|000010c0| 20 62 65 20 75 73 65 64 | 20 74 6f 20 63 72 65 61 | be used| to crea|
|000010d0| 74 65 64 20 70 72 6f 67 | 72 61 6d 73 0a 74 68 61 |ted prog|rams.tha|
|000010e0| 74 20 6c 6f 61 64 20 74 | 68 65 20 61 70 70 72 6f |t load t|he appro|
|000010f0| 70 72 69 61 74 65 20 6c | 69 62 72 61 72 79 20 61 |priate l|ibrary a|
|00001100| 74 20 73 74 61 72 74 75 | 70 2e 0a 0a 4e 6f 74 65 |t startu|p...Note|
|00001110| 20 74 68 61 74 20 74 68 | 65 20 64 65 66 69 6e 69 | that th|e defini|
|00001120| 74 69 6f 6e 20 6f 66 20 | 74 68 65 20 66 6f 72 65 |tion of |the fore|
|00001130| 69 67 6e 20 70 72 65 64 | 69 63 61 74 65 73 20 69 |ign pred|icates i|
|00001140| 73 20 74 68 65 20 73 61 | 6d 65 2c 20 72 65 67 61 |s the sa|me, rega|
|00001150| 72 64 6c 65 73 73 0a 6f | 66 20 74 68 65 20 6c 69 |rdless.o|f the li|
|00001160| 6e 6b 69 6e 67 20 74 79 | 70 65 20 75 73 65 64 2e |nking ty|pe used.|
|00001170| 0a 0a 0a 5c 73 65 63 74 | 69 6f 6e 7b 44 79 6e 61 |...\sect|ion{Dyna|
|00001180| 6d 69 63 20 4c 69 6e 6b | 69 6e 67 20 6f 66 20 73 |mic Link|ing of s|
|00001190| 68 61 72 65 64 20 6c 69 | 62 72 61 72 69 65 73 7d |hared li|braries}|
|000011a0| 0a 0a 54 68 65 20 69 6e | 74 65 72 66 61 63 65 20 |..The in|terface |
|000011b0| 64 65 66 69 6e 65 64 20 | 69 6e 20 74 68 69 73 20 |defined |in this |
|000011c0| 73 65 63 74 69 6f 6e 20 | 61 6c 6c 6f 77 73 20 74 |section |allows t|
|000011d0| 68 65 20 75 73 65 72 20 | 74 6f 20 6c 6f 61 64 20 |he user |to load |
|000011e0| 73 68 61 72 65 64 0a 6c | 69 62 72 61 72 69 65 73 |shared.l|ibraries|
|000011f0| 20 28 5c 66 69 6c 65 65 | 78 74 7b 73 6f 7d 20 66 | (\filee|xt{so} f|
|00001200| 69 6c 65 73 20 6f 6e 20 | 6d 6f 73 74 20 55 6e 69 |iles on |most Uni|
|00001210| 78 20 73 79 73 74 65 6d | 73 29 2e 20 54 68 69 73 |x system|s). This|
|00001220| 20 69 6e 74 65 72 66 61 | 63 65 20 69 73 0a 70 6f | interfa|ce is.po|
|00001230| 72 74 61 62 6c 65 20 74 | 6f 20 61 6c 6c 20 6d 61 |rtable t|o all ma|
|00001240| 63 68 69 6e 65 73 20 70 | 72 6f 76 69 64 69 6e 67 |chines p|roviding|
|00001250| 20 74 68 65 20 66 75 6e | 63 74 69 6f 6e 20 5c 6d | the fun|ction \m|
|00001260| 61 6e 72 65 66 7b 64 6c | 6f 70 65 6e 7d 7b 32 7d |anref{dl|open}{2}|
|00001270| 20 6f 72 20 61 6e 0a 65 | 71 75 69 76 61 6c 65 6e | or an.e|quivalen|
|00001280| 74 2c 20 6e 6f 72 6d 61 | 6c 6c 79 20 66 72 6f 6d |t, norma|lly from|
|00001290| 20 74 68 65 20 6c 69 62 | 72 61 72 79 20 5c 63 6c | the lib|rary \cl|
|000012a0| 69 62 7b 2d 6c 64 6c 7d | 2e 20 54 68 65 73 65 20 |ib{-ldl}|. These |
|000012b0| 66 75 6e 63 74 69 6f 6e | 73 0a 70 72 6f 76 69 64 |function|s.provid|
|000012c0| 65 20 74 68 65 20 62 61 | 73 69 63 20 69 6e 74 65 |e the ba|sic inte|
|000012d0| 72 66 61 63 65 20 6c 61 | 79 65 72 2e 20 49 74 20 |rface la|yer. It |
|000012e0| 69 73 20 61 64 76 69 73 | 65 64 20 74 6f 20 75 73 |is advis|ed to us|
|000012f0| 65 20 74 68 65 20 70 72 | 65 64 69 63 61 74 65 73 |e the pr|edicates|
|00001300| 0a 66 72 6f 6d 20 5c 73 | 65 63 72 65 66 7b 73 68 |.from \s|ecref{sh|
|00001310| 6c 69 62 7d 20 69 6e 20 | 79 6f 75 72 20 61 70 70 |lib} in |your app|
|00001320| 6c 69 63 61 74 69 6f 6e | 2e 0a 0a 0a 5c 62 65 67 |lication|....\beg|
|00001330| 69 6e 7b 64 65 73 63 72 | 69 70 74 69 6f 6e 7d 0a |in{descr|iption}.|
|00001340| 20 20 20 20 5c 70 72 65 | 64 69 63 61 74 65 7b 6f | \pre|dicate{o|
|00001350| 70 65 6e 5f 73 68 61 72 | 65 64 5f 6f 62 6a 65 63 |pen_shar|ed_objec|
|00001360| 74 7d 7b 32 7d 7b 2b 46 | 69 6c 65 2c 20 2d 48 61 |t}{2}{+F|ile, -Ha|
|00001370| 6e 64 6c 65 7d 0a 5c 61 | 72 67 7b 46 69 6c 65 7d |ndle}.\a|rg{File}|
|00001380| 20 69 73 20 74 68 65 20 | 6e 61 6d 65 20 6f 66 20 | is the |name of |
|00001390| 61 20 5c 66 69 6c 65 65 | 78 74 7b 73 6f 7d 20 66 |a \filee|xt{so} f|
|000013a0| 69 6c 65 20 28 73 65 65 | 20 79 6f 75 72 20 43 20 |ile (see| your C |
|000013b0| 70 72 6f 67 72 61 6d 6d | 65 72 73 0a 64 6f 63 75 |programm|ers.docu|
|000013c0| 6d 65 6e 74 61 74 69 6f | 6e 20 6f 6e 20 68 6f 77 |mentatio|n on how|
|000013d0| 20 74 6f 20 63 72 65 61 | 74 65 20 61 20 5c 66 69 | to crea|te a \fi|
|000013e0| 6c 65 65 78 74 7b 73 6f | 7d 20 66 69 6c 65 29 2e |leext{so|} file).|
|000013f0| 20 54 68 69 73 20 66 69 | 6c 65 20 69 73 0a 61 74 | This fi|le is.at|
|00001400| 74 61 63 68 65 64 20 74 | 6f 20 74 68 65 20 63 75 |tached t|o the cu|
|00001410| 72 72 65 6e 74 20 70 72 | 6f 63 65 73 73 20 61 6e |rrent pr|ocess an|
|00001420| 64 20 5c 61 72 67 7b 48 | 61 6e 64 6c 65 7d 20 69 |d \arg{H|andle} i|
|00001430| 73 20 75 6e 69 66 69 65 | 64 20 77 69 74 68 20 61 |s unifie|d with a|
|00001440| 0a 68 61 6e 64 6c 65 20 | 74 6f 20 74 68 65 20 73 |.handle |to the s|
|00001450| 68 61 72 65 64 20 6f 62 | 6a 65 63 74 2e 20 45 71 |hared ob|ject. Eq|
|00001460| 75 69 76 61 6c 65 6e 74 | 20 74 6f 0a 5c 65 78 61 |uivalent| to.\exa|
|00001470| 6d 7b 6f 70 65 6e 5f 73 | 68 61 72 65 64 5f 6f 62 |m{open_s|hared_ob|
|00001480| 6a 65 63 74 28 46 69 6c | 65 2c 20 5b 67 6c 6f 62 |ject(Fil|e, [glob|
|00001490| 61 6c 5d 2c 20 48 61 6e | 64 6c 65 29 7d 2e 20 53 |al], Han|dle)}. S|
|000014a0| 65 65 20 61 6c 73 6f 0a | 6c 6f 61 64 5f 66 6f 72 |ee also.|load_for|
|000014b0| 65 69 67 6e 5f 6c 69 62 | 72 61 72 79 2f 5b 31 2c |eign_lib|rary/[1,|
|000014c0| 32 5d 2e 0a 0a 20 20 20 | 20 5c 70 72 65 64 69 63 |2]... | \predic|
|000014d0| 61 74 65 7b 6f 70 65 6e | 5f 73 68 61 72 65 64 5f |ate{open|_shared_|
|000014e0| 6f 62 6a 65 63 74 7d 7b | 33 7d 7b 2b 46 69 6c 65 |object}{|3}{+File|
|000014f0| 2c 20 2b 4f 70 74 69 6f | 6e 73 2c 20 2d 48 61 6e |, +Optio|ns, -Han|
|00001500| 64 6c 65 7d 0a 41 73 20 | 6f 70 65 6e 5f 73 68 61 |dle}.As |open_sha|
|00001510| 72 65 64 5f 6f 62 6a 65 | 63 74 2f 32 2c 20 62 75 |red_obje|ct/2, bu|
|00001520| 74 20 61 6c 6c 6f 77 73 | 20 66 6f 72 20 61 64 64 |t allows| for add|
|00001530| 69 74 69 6f 6e 61 6c 20 | 66 6c 61 67 73 20 74 6f |itional |flags to|
|00001540| 20 62 65 20 70 61 73 73 | 65 64 2e 0a 5c 61 72 67 | be pass|ed..\arg|
|00001550| 7b 4f 70 74 69 6f 6e 73 | 7d 20 69 73 20 61 20 6c |{Options|} is a l|
|00001560| 69 73 74 20 6f 66 20 61 | 74 6f 6d 73 2e 20 5c 63 |ist of a|toms. \c|
|00001570| 6f 6e 73 74 7b 6e 6f 77 | 7d 20 69 6d 70 6c 69 65 |onst{now|} implie|
|00001580| 73 20 74 68 65 20 73 79 | 6d 62 6f 6c 73 20 61 72 |s the sy|mbols ar|
|00001590| 65 0a 72 65 73 6f 6c 76 | 65 64 20 69 6d 6d 65 64 |e.resolv|ed immed|
|000015a0| 69 61 74 65 6c 79 20 72 | 61 74 68 65 72 20 74 68 |iately r|ather th|
|000015b0| 61 6e 20 6c 61 7a 79 20 | 28 64 65 66 61 75 6c 74 |an lazy |(default|
|000015c0| 29 2e 20 5c 63 6f 6e 73 | 74 7b 67 6c 6f 62 61 6c |). \cons|t{global|
|000015d0| 7d 20 69 6d 70 6c 69 65 | 73 0a 73 79 6d 62 6f 6c |} implie|s.symbol|
|000015e0| 73 20 6f 66 20 74 68 65 | 20 6c 6f 61 64 65 64 20 |s of the| loaded |
|000015f0| 6f 62 6a 65 63 74 20 61 | 72 65 20 76 69 73 69 62 |object a|re visib|
|00001600| 6c 65 20 77 68 69 6c 65 | 20 6c 6f 61 64 69 6e 67 |le while| loading|
|00001610| 20 6f 74 68 65 72 20 73 | 68 61 72 65 64 0a 6f 62 | other s|hared.ob|
|00001620| 6a 65 63 74 73 20 28 62 | 79 20 64 65 66 61 75 6c |jects (b|y defaul|
|00001630| 74 20 74 68 65 79 20 61 | 72 65 20 6c 6f 63 61 6c |t they a|re local|
|00001640| 29 2e 20 4e 6f 74 65 20 | 74 68 61 74 20 74 68 65 |). Note |that the|
|00001650| 73 65 20 66 6c 61 67 73 | 20 6d 61 79 20 6e 6f 74 |se flags| may not|
|00001660| 20 62 65 0a 73 75 70 70 | 6f 72 74 65 64 20 62 79 | be.supp|orted by|
|00001670| 20 79 6f 75 72 20 6f 70 | 65 72 61 74 69 6e 67 20 | your op|erating |
|00001680| 73 79 73 74 65 6d 2e 20 | 43 68 65 63 6b 20 74 68 |system. |Check th|
|00001690| 65 20 64 6f 63 75 6d 65 | 6e 74 61 74 69 6f 6e 20 |e docume|ntation |
|000016a0| 6f 66 20 64 6c 6f 70 65 | 6e 28 29 0a 6f 72 20 65 |of dlope|n().or e|
|000016b0| 71 75 69 76 61 6c 65 6e | 74 20 6f 6e 20 79 6f 75 |quivalen|t on you|
|000016c0| 72 20 6f 70 65 72 61 74 | 69 6e 67 20 73 79 73 74 |r operat|ing syst|
|000016d0| 65 6d 2e 0a 0a 20 20 20 | 20 5c 70 72 65 64 69 63 |em... | \predic|
|000016e0| 61 74 65 7b 63 6c 6f 73 | 65 5f 73 68 61 72 65 64 |ate{clos|e_shared|
|000016f0| 5f 6f 62 6a 65 63 74 7d | 7b 31 7d 7b 2b 48 61 6e |_object}|{1}{+Han|
|00001700| 64 6c 65 7d 0a 44 65 74 | 61 63 68 20 74 68 65 20 |dle}.Det|ach the |
|00001710| 73 68 61 72 65 64 20 6f | 62 6a 65 63 74 20 69 64 |shared o|bject id|
|00001720| 65 6e 74 69 66 69 65 64 | 20 62 79 20 5c 61 72 67 |entified| by \arg|
|00001730| 7b 48 61 6e 64 6c 65 7d | 2e 0a 0a 20 20 20 20 5c |{Handle}|... \|
|00001740| 70 72 65 64 69 63 61 74 | 65 7b 63 61 6c 6c 5f 73 |predicat|e{call_s|
|00001750| 68 61 72 65 64 5f 6f 62 | 6a 65 63 74 5f 66 75 6e |hared_ob|ject_fun|
|00001760| 63 74 69 6f 6e 7d 7b 32 | 7d 7b 2b 48 61 6e 64 6c |ction}{2|}{+Handl|
|00001770| 65 2c 20 2b 46 75 6e 63 | 74 69 6f 6e 7d 0a 43 61 |e, +Func|tion}.Ca|
|00001780| 6c 6c 20 74 68 65 20 6e | 61 6d 65 64 20 66 75 6e |ll the n|amed fun|
|00001790| 63 74 69 6f 6e 20 69 6e | 20 74 68 65 20 6c 6f 61 |ction in| the loa|
|000017a0| 64 65 64 20 73 68 61 72 | 65 64 20 6c 69 62 72 61 |ded shar|ed libra|
|000017b0| 72 79 2e 20 20 54 68 65 | 20 66 75 6e 63 74 69 6f |ry. The| functio|
|000017c0| 6e 0a 69 73 20 63 61 6c | 6c 65 64 20 77 69 74 68 |n.is cal|led with|
|000017d0| 6f 75 74 20 61 72 67 75 | 6d 65 6e 74 73 20 61 6e |out argu|ments an|
|000017e0| 64 20 74 68 65 20 72 65 | 74 75 72 6e 2d 76 61 6c |d the re|turn-val|
|000017f0| 75 65 20 69 73 20 69 67 | 6e 6f 72 65 64 2e 20 20 |ue is ig|nored. |
|00001800| 4e 6f 72 6d 61 6c 6c 79 | 0a 74 68 69 73 20 66 75 |Normally|.this fu|
|00001810| 6e 63 74 69 6f 6e 20 69 | 6e 73 74 61 6c 6c 73 20 |nction i|nstalls |
|00001820| 66 6f 72 65 69 67 6e 20 | 6c 61 6e 67 75 61 67 65 |foreign |language|
|00001830| 20 70 72 65 64 69 63 61 | 74 65 73 20 75 73 69 6e | predica|tes usin|
|00001840| 67 20 63 61 6c 6c 73 20 | 74 6f 0a 50 4c 5f 72 65 |g calls |to.PL_re|
|00001850| 67 69 73 74 65 72 5f 66 | 6f 72 65 69 67 6e 28 29 |gister_f|oreign()|
|00001860| 2e 0a 5c 65 6e 64 7b 64 | 65 73 63 72 69 70 74 69 |..\end{d|escripti|
|00001870| 6f 6e 7d 0a 0a 0a 5c 73 | 65 63 74 69 6f 6e 7b 55 |on}...\s|ection{U|
|00001880| 73 69 6e 67 20 74 68 65 | 20 6c 69 62 72 61 72 79 |sing the| library|
|00001890| 20 73 68 6c 69 62 20 66 | 6f 72 20 5c 66 69 6c 65 | shlib f|or \file|
|000018a0| 65 78 74 7b 44 4c 4c 7d | 20 61 6e 64 20 5c 66 69 |ext{DLL}| and \fi|
|000018b0| 6c 65 65 78 74 7b 73 6f | 7d 20 66 69 6c 65 73 7d |leext{so|} files}|
|000018c0| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |. | |
|000018d0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000018e0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000018f0| 20 20 20 20 20 20 20 20 | 20 20 5c 6c 61 62 65 6c | | \label|
|00001900| 7b 73 65 63 3a 44 4c 4c | 7d 0a 20 20 20 20 20 20 |{sec:DLL|}. |
|00001910| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001920| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001930| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00001940| 20 20 20 5c 6c 61 62 65 | 6c 7b 73 65 63 3a 73 68 | \labe|l{sec:sh|
|00001950| 6c 69 62 7d 0a 0a 54 68 | 69 73 20 73 65 63 74 69 |lib}..Th|is secti|
|00001960| 6f 6e 20 64 69 73 63 75 | 73 73 65 73 20 74 68 65 |on discu|sses the|
|00001970| 20 66 75 6e 63 74 69 6f | 6e 61 6c 69 74 79 20 6f | functio|nality o|
|00001980| 66 20 74 68 65 20 28 61 | 75 74 6f 6c 6f 61 64 29 |f the (a|utoload)|
|00001990| 20 6c 69 62 72 61 72 79 | 0a 5c 66 69 6c 65 7b 73 | library|.\file{s|
|000019a0| 68 6c 69 62 2e 70 6c 7d | 2c 20 70 72 6f 76 69 64 |hlib.pl}|, provid|
|000019b0| 69 6e 67 20 61 6e 20 69 | 6e 74 65 72 66 61 63 65 |ing an i|nterface|
|000019c0| 20 74 6f 20 73 68 61 72 | 65 64 20 6c 69 62 72 61 | to shar|ed libra|
|000019d0| 72 69 65 73 2e 20 43 75 | 72 72 65 6e 74 6c 79 0a |ries. Cu|rrently.|
|000019e0| 69 74 20 73 75 70 70 6f | 72 74 73 20 4d 53 2d 57 |it suppo|rts MS-W|
|000019f0| 69 6e 64 6f 77 73 20 44 | 4c 4c 20 28 5c 66 69 6c |indows D|LL (\fil|
|00001a00| 65 65 78 74 7b 44 4c 4c | 7d 29 20 6c 69 62 72 61 |eext{DLL|}) libra|
|00001a10| 72 69 65 73 20 61 6e 64 | 20 55 6e 69 78 0a 5c 66 |ries and| Unix.\f|
|00001a20| 69 6c 65 65 78 74 7b 73 | 6f 7d 20 28 73 68 61 72 |ileext{s|o} (shar|
|00001a30| 65 64 20 6f 62 6a 65 63 | 74 29 20 66 69 6c 65 73 |ed objec|t) files|
|00001a40| 2e 0a 0a 5c 62 65 67 69 | 6e 7b 64 65 73 63 72 69 |...\begi|n{descri|
|00001a50| 70 74 69 6f 6e 7d 0a 5c | 70 72 65 64 69 63 61 74 |ption}.\|predicat|
|00001a60| 65 7b 6c 6f 61 64 5f 66 | 6f 72 65 69 67 6e 5f 6c |e{load_f|oreign_l|
|00001a70| 69 62 72 61 72 79 7d 7b | 31 7d 7b 2b 4c 69 62 7d |ibrary}{|1}{+Lib}|
|00001a80| 0a 45 71 75 69 76 61 6c | 65 6e 74 20 74 6f 20 6c |.Equival|ent to l|
|00001a90| 6f 61 64 5f 66 6f 72 65 | 69 67 6e 5f 6c 69 62 72 |oad_fore|ign_libr|
|00001aa0| 61 72 79 28 4c 69 62 2c | 20 69 6e 73 74 61 6c 6c |ary(Lib,| install|
|00001ab0| 29 2e 0a 5c 70 72 65 64 | 69 63 61 74 65 7b 6c 6f |)..\pred|icate{lo|
|00001ac0| 61 64 5f 66 6f 72 65 69 | 67 6e 5f 6c 69 62 72 61 |ad_forei|gn_libra|
|00001ad0| 72 79 7d 7b 32 7d 7b 2b | 4c 69 62 2c 20 2b 45 6e |ry}{2}{+|Lib, +En|
|00001ae0| 74 72 79 7d 0a 53 65 61 | 72 63 68 20 66 6f 72 20 |try}.Sea|rch for |
|00001af0| 74 68 65 20 67 69 76 65 | 6e 20 66 6f 72 65 69 67 |the give|n foreig|
|00001b00| 6e 20 6c 69 62 72 61 72 | 79 20 61 6e 64 20 6c 69 |n librar|y and li|
|00001b10| 6e 6b 20 69 74 20 74 6f | 20 74 68 65 20 63 75 72 |nk it to| the cur|
|00001b20| 72 65 6e 74 0a 53 57 49 | 2d 50 72 6f 6c 6f 67 20 |rent.SWI|-Prolog |
|00001b30| 69 6e 73 74 61 6e 63 65 | 2e 20 20 54 68 65 20 6c |instance|. The l|
|00001b40| 69 62 72 61 72 79 20 6d | 61 79 20 62 65 20 73 70 |ibrary m|ay be sp|
|00001b50| 65 63 69 66 69 65 64 20 | 77 69 74 68 20 6f 72 20 |ecified |with or |
|00001b60| 77 69 74 68 6f 75 74 20 | 74 68 65 0a 65 78 74 65 |without |the.exte|
|00001b70| 6e 73 69 6f 6e 2e 20 20 | 46 69 72 73 74 2c 20 61 |nsion. |First, a|
|00001b80| 62 73 6f 6c 75 74 65 5f | 66 69 6c 65 5f 6e 61 6d |bsolute_|file_nam|
|00001b90| 65 2f 33 20 69 73 20 75 | 73 65 64 20 74 6f 20 6c |e/3 is u|sed to l|
|00001ba0| 6f 63 61 74 65 20 74 68 | 65 20 66 69 6c 65 2e 20 |ocate th|e file. |
|00001bb0| 20 49 66 0a 74 68 69 73 | 20 73 75 63 63 65 65 64 | If.this| succeed|
|00001bc0| 73 2c 20 74 68 65 20 66 | 75 6c 6c 20 70 61 74 68 |s, the f|ull path|
|00001bd0| 20 69 73 20 70 61 73 73 | 65 64 20 74 6f 20 74 68 | is pass|ed to th|
|00001be0| 65 20 6c 6f 77 2d 6c 65 | 76 65 6c 20 66 75 6e 63 |e low-le|vel func|
|00001bf0| 74 69 6f 6e 20 74 6f 20 | 6f 70 65 6e 0a 74 68 65 |tion to |open.the|
|00001c00| 20 6c 69 62 72 61 72 79 | 2e 20 20 4f 74 68 65 72 | library|. Other|
|00001c10| 77 69 73 65 2c 20 74 68 | 65 20 70 6c 61 69 6e 20 |wise, th|e plain |
|00001c20| 6c 69 62 72 61 72 79 20 | 6e 61 6d 65 20 69 73 20 |library |name is |
|00001c30| 70 61 73 73 65 64 2c 20 | 65 78 70 6c 6f 69 74 69 |passed, |exploiti|
|00001c40| 6e 67 0a 74 68 65 20 6f | 70 65 72 61 74 69 6e 67 |ng.the o|perating|
|00001c50| 2d 73 79 73 74 65 6d 20 | 64 65 66 69 6e 65 64 20 |-system |defined |
|00001c60| 73 65 61 72 63 68 20 6d | 65 63 68 61 6e 69 73 6d |search m|echanism|
|00001c70| 20 66 6f 72 20 74 68 65 | 20 73 68 61 72 65 64 20 | for the| shared |
|00001c80| 6c 69 62 72 61 72 79 2e | 0a 54 68 65 20 66 69 6c |library.|.The fil|
|00001c90| 65 5f 73 65 61 72 63 68 | 5f 70 61 74 68 2f 32 20 |e_search|_path/2 |
|00001ca0| 61 6c 69 61 73 20 6d 65 | 63 68 61 6e 69 73 6d 20 |alias me|chanism |
|00001cb0| 64 65 66 69 6e 65 73 20 | 74 68 65 20 61 6c 69 61 |defines |the alia|
|00001cc0| 73 20 5c 63 6f 6e 73 74 | 7b 66 6f 72 65 69 67 6e |s \const|{foreign|
|00001cd0| 7d 2c 0a 77 68 69 63 68 | 20 72 65 66 65 72 73 20 |},.which| refers |
|00001ce0| 74 6f 20 74 68 65 20 64 | 69 72 65 63 74 6f 72 69 |to the d|irectori|
|00001cf0| 65 73 20 5c 66 69 6c 65 | 7b 3c 70 6c 68 6f 6d 65 |es \file|{<plhome|
|00001d00| 3e 2f 6c 69 62 2f 3c 61 | 72 63 68 3e 7d 20 61 6e |>/lib/<a|rch>} an|
|00001d10| 64 0a 5c 66 69 6c 65 7b | 3c 70 6c 68 6f 6d 65 3e |d.\file{|<plhome>|
|00001d20| 2f 6c 69 62 7d 2c 20 69 | 6e 20 74 68 69 73 20 6f |/lib}, i|n this o|
|00001d30| 72 64 65 72 2e 0a 0a 49 | 66 20 74 68 65 20 6c 69 |rder...I|f the li|
|00001d40| 62 72 61 72 79 20 63 61 | 6e 20 62 65 20 6c 6f 61 |brary ca|n be loa|
|00001d50| 64 65 64 2c 20 74 68 65 | 20 66 75 6e 63 74 69 6f |ded, the| functio|
|00001d60| 6e 20 63 61 6c 6c 65 64 | 20 5c 61 72 67 7b 45 6e |n called| \arg{En|
|00001d70| 74 72 79 7d 20 77 69 6c | 6c 20 62 65 0a 63 61 6c |try} wil|l be.cal|
|00001d80| 6c 65 64 20 77 69 74 68 | 6f 75 74 20 61 72 67 75 |led with|out argu|
|00001d90| 6d 65 6e 74 73 2e 20 54 | 68 65 20 72 65 74 75 72 |ments. T|he retur|
|00001da0| 6e 20 76 61 6c 75 65 20 | 6f 66 20 74 68 65 20 66 |n value |of the f|
|00001db0| 75 6e 63 74 69 6f 6e 20 | 69 73 20 69 67 6e 6f 72 |unction |is ignor|
|00001dc0| 65 64 2e 0a 0a 54 68 65 | 20 5c 61 72 67 7b 45 6e |ed...The| \arg{En|
|00001dd0| 74 72 79 7d 20 66 75 6e | 63 74 69 6f 6e 20 77 69 |try} fun|ction wi|
|00001de0| 6c 6c 20 6e 6f 72 6d 61 | 6c 6c 79 20 63 61 6c 6c |ll norma|lly call|
|00001df0| 20 50 4c 5f 72 65 67 69 | 73 74 65 72 5f 66 6f 72 | PL_regi|ster_for|
|00001e00| 65 69 67 6e 28 29 20 74 | 6f 0a 64 65 63 6c 61 72 |eign() t|o.declar|
|00001e10| 65 20 66 75 6e 63 74 69 | 6f 6e 73 20 69 6e 20 74 |e functi|ons in t|
|00001e20| 68 65 20 6c 69 62 72 61 | 72 79 20 61 73 20 66 6f |he libra|ry as fo|
|00001e30| 72 65 69 67 6e 20 70 72 | 65 64 69 63 61 74 65 73 |reign pr|edicates|
|00001e40| 2e 0a 5c 70 72 65 64 69 | 63 61 74 65 7b 75 6e 6c |..\predi|cate{unl|
|00001e50| 6f 61 64 5f 66 6f 72 65 | 69 67 6e 5f 6c 69 62 72 |oad_fore|ign_libr|
|00001e60| 61 72 79 7d 7b 31 7d 7b | 2b 4c 69 62 7d 0a 49 66 |ary}{1}{|+Lib}.If|
|00001e70| 20 74 68 65 20 66 6f 72 | 65 69 67 6e 20 6c 69 62 | the for|eign lib|
|00001e80| 72 61 72 79 20 64 65 66 | 69 6e 65 73 20 74 68 65 |rary def|ines the|
|00001e90| 20 66 75 6e 63 74 69 6f | 6e 20 75 6e 69 6e 73 74 | functio|n uninst|
|00001ea0| 61 6c 6c 28 29 2c 20 74 | 68 69 73 0a 66 75 6e 63 |all(), t|his.func|
|00001eb0| 74 69 6f 6e 20 77 69 6c | 6c 20 62 65 20 63 61 6c |tion wil|l be cal|
|00001ec0| 6c 65 64 20 77 69 74 68 | 6f 75 74 20 61 72 67 75 |led with|out argu|
|00001ed0| 6d 65 6e 74 73 20 61 6e | 64 20 69 74 73 20 72 65 |ments an|d its re|
|00001ee0| 74 75 72 6e 20 76 61 6c | 75 65 20 69 73 0a 69 67 |turn val|ue is.ig|
|00001ef0| 6e 6f 72 65 64 2e 20 20 | 4e 65 78 74 2c 20 61 62 |nored. |Next, ab|
|00001f00| 6f 6c 69 73 68 2f 32 20 | 69 73 20 75 73 65 64 20 |olish/2 |is used |
|00001f10| 74 6f 20 72 65 6d 6f 76 | 65 20 61 6c 6c 20 6b 6e |to remov|e all kn|
|00001f20| 6f 77 6e 20 66 6f 72 65 | 69 67 6e 20 70 72 65 64 |own fore|ign pred|
|00001f30| 69 63 61 74 65 73 0a 64 | 65 66 69 6e 65 64 20 69 |icates.d|efined i|
|00001f40| 6e 20 74 68 65 20 6c 69 | 62 72 61 72 79 2e 20 46 |n the li|brary. F|
|00001f50| 69 6e 61 6c 6c 79 20 74 | 68 65 20 6c 69 62 72 61 |inally t|he libra|
|00001f60| 72 79 20 69 74 73 65 6c | 66 20 69 73 20 64 65 74 |ry itsel|f is det|
|00001f70| 61 63 68 65 64 20 66 72 | 6f 6d 20 74 68 65 0a 70 |ached fr|om the.p|
|00001f80| 72 6f 63 65 73 73 2e 0a | 5c 70 72 65 64 69 63 61 |rocess..|\predica|
|00001f90| 74 65 7b 63 75 72 72 65 | 6e 74 5f 66 6f 72 65 69 |te{curre|nt_forei|
|00001fa0| 67 6e 5f 6c 69 62 72 61 | 72 79 7d 7b 32 7d 7b 2d |gn_libra|ry}{2}{-|
|00001fb0| 4c 69 62 2c 20 2d 50 72 | 65 64 69 63 61 74 65 73 |Lib, -Pr|edicates|
|00001fc0| 7d 0a 51 75 65 72 79 20 | 74 68 65 20 63 75 72 72 |}.Query |the curr|
|00001fd0| 65 6e 74 6c 79 20 6c 6f | 61 64 65 64 20 66 6f 72 |ently lo|aded for|
|00001fe0| 65 69 67 6e 20 6c 69 62 | 72 61 72 69 65 73 20 61 |eign lib|raries a|
|00001ff0| 6e 64 20 74 68 65 69 72 | 20 70 72 65 64 69 63 61 |nd their| predica|
|00002000| 74 65 73 2e 20 20 7b 5c | 65 6d 0a 50 72 65 64 69 |tes. {\|em.Predi|
|00002010| 63 61 74 65 73 7d 20 69 | 73 20 61 20 6c 69 73 74 |cates} i|s a list|
|00002020| 20 77 69 74 68 20 65 6c | 65 6d 65 6e 74 73 20 6f | with el|ements o|
|00002030| 66 20 74 68 65 20 66 6f | 72 6d 20 7b 5c 65 6d 20 |f the fo|rm {\em |
|00002040| 4d 6f 64 75 6c 65 3a 48 | 65 61 64 7d 2c 0a 69 6e |Module:H|ead},.in|
|00002050| 64 69 63 61 74 69 6e 67 | 20 74 68 65 20 70 72 65 |dicating| the pre|
|00002060| 64 69 63 61 74 65 73 20 | 69 6e 73 74 61 6c 6c 65 |dicates |installe|
|00002070| 64 20 77 69 74 68 20 50 | 4c 5f 72 65 67 69 73 74 |d with P|L_regist|
|00002080| 65 72 5f 66 6f 72 65 69 | 67 6e 28 29 20 77 68 65 |er_forei|gn() whe|
|00002090| 6e 0a 74 68 65 20 65 6e | 74 72 79 2d 70 6f 69 6e |n.the en|try-poin|
|000020a0| 74 20 6f 66 20 74 68 65 | 20 6c 69 62 72 61 72 79 |t of the| library|
|000020b0| 20 77 61 73 20 63 61 6c | 6c 65 64 2e 0a 5c 65 6e | was cal|led..\en|
|000020c0| 64 7b 64 65 73 63 72 69 | 70 74 69 6f 6e 7d 0a 0a |d{descri|ption}..|
|000020d0| 5c 46 69 67 72 65 66 7b | 6d 73 67 62 6f 78 7d 20 |\Figref{|msgbox} |
|000020e0| 63 6f 6e 6e 65 63 74 73 | 20 61 20 57 69 6e 64 6f |connects| a Windo|
|000020f0| 77 73 20 6d 65 73 73 61 | 67 65 2d 62 6f 78 20 75 |ws messa|ge-box u|
|00002100| 73 69 6e 67 20 61 20 66 | 6f 72 65 69 67 6e 0a 66 |sing a f|oreign.f|
|00002110| 75 6e 63 74 69 6f 6e 2e | 20 20 54 68 69 73 20 65 |unction.| This e|
|00002120| 78 61 6d 70 6c 65 20 77 | 61 73 20 74 65 73 74 65 |xample w|as teste|
|00002130| 64 20 75 73 69 6e 67 20 | 57 69 6e 64 6f 77 73 7e |d using |Windows~|
|00002140| 4e 54 20 61 6e 64 20 4d | 69 63 72 6f 73 6f 66 74 |NT and M|icrosoft|
|00002150| 20 56 69 73 75 61 6c 0a | 43 2b 2b 20 32 2e 30 2e | Visual.|C++ 2.0.|
|00002160| 0a 0a 5c 62 65 67 69 6e | 7b 66 69 67 75 72 65 7d |..\begin|{figure}|
|00002170| 5b 68 5d 0a 5c 62 65 67 | 69 6e 7b 63 6f 64 65 7d |[h].\beg|in{code}|
|00002180| 0a 23 69 6e 63 6c 75 64 | 65 20 3c 77 69 6e 64 6f |.#includ|e <windo|
|00002190| 77 73 2e 68 3e 0a 23 69 | 6e 63 6c 75 64 65 20 3c |ws.h>.#i|nclude <|
|000021a0| 53 57 49 2d 50 72 6f 6c | 6f 67 2e 68 3e 0a 0a 73 |SWI-Prol|og.h>..s|
|000021b0| 74 61 74 69 63 20 66 6f | 72 65 69 67 6e 5f 74 0a |tatic fo|reign_t.|
|000021c0| 70 6c 5f 73 61 79 5f 68 | 65 6c 6c 6f 28 74 65 72 |pl_say_h|ello(ter|
|000021d0| 6d 5f 74 20 74 6f 29 0a | 7b 20 63 68 61 72 20 2a |m_t to).|{ char *|
|000021e0| 61 3b 0a 0a 20 20 69 66 | 20 28 20 50 4c 5f 67 65 |a;.. if| ( PL_ge|
|000021f0| 74 5f 61 74 6f 6d 5f 63 | 68 61 72 73 28 74 6f 2c |t_atom_c|hars(to,|
|00002200| 20 26 61 29 20 29 0a 20 | 20 7b 20 4d 65 73 73 61 | &a) ). | { Messa|
|00002210| 67 65 42 6f 78 28 4e 55 | 4c 4c 2c 20 61 2c 20 22 |geBox(NU|LL, a, "|
|00002220| 44 4c 4c 20 74 65 73 74 | 22 2c 20 4d 42 5f 4f 4b |DLL test|", MB_OK|
|00002230| 7c 4d 42 5f 54 41 53 4b | 4d 4f 44 41 4c 29 3b 0a ||MB_TASK|MODAL);.|
|00002240| 0a 20 20 20 20 50 4c 5f | 73 75 63 63 65 65 64 3b |. PL_|succeed;|
|00002250| 0a 20 20 7d 0a 0a 20 20 | 50 4c 5f 66 61 69 6c 3b |. }.. |PL_fail;|
|00002260| 0a 7d 0a 0a 69 6e 73 74 | 61 6c 6c 5f 74 0a 69 6e |.}..inst|all_t.in|
|00002270| 73 74 61 6c 6c 28 29 0a | 7b 20 50 4c 5f 72 65 67 |stall().|{ PL_reg|
|00002280| 69 73 74 65 72 5f 66 6f | 72 65 69 67 6e 28 22 73 |ister_fo|reign("s|
|00002290| 61 79 5f 68 65 6c 6c 6f | 22 2c 20 31 2c 20 70 6c |ay_hello|", 1, pl|
|000022a0| 5f 73 61 79 5f 68 65 6c | 6c 6f 2c 20 30 29 3b 0a |_say_hel|lo, 0);.|
|000022b0| 7d 0a 5c 65 6e 64 7b 63 | 6f 64 65 7d 0a 20 20 20 |}.\end{c|ode}. |
|000022c0| 20 5c 63 61 70 74 69 6f | 6e 7b 4d 65 73 73 61 67 | \captio|n{Messag|
|000022d0| 65 42 6f 78 28 29 20 65 | 78 61 6d 70 6c 65 20 69 |eBox() e|xample i|
|000022e0| 6e 20 57 69 6e 64 6f 77 | 73 7e 4e 54 7d 0a 20 20 |n Window|s~NT}. |
|000022f0| 20 20 5c 6c 61 62 65 6c | 7b 66 69 67 3a 6d 73 67 | \label|{fig:msg|
|00002300| 62 6f 78 7d 0a 5c 65 6e | 64 7b 66 69 67 75 72 65 |box}.\en|d{figure|
|00002310| 7d 0a 0a 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |}...\sub|section{|
|00002320| 53 74 61 74 69 63 20 4c | 69 6e 6b 69 6e 67 7d 20 |Static L|inking} |
|00002330| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00002340| 20 20 20 20 20 20 20 20 | 20 20 20 20 5c 6c 61 62 | | \lab|
|00002350| 65 6c 7b 73 65 63 3a 73 | 74 61 74 69 63 6c 7d 0a |el{sec:s|taticl}.|
|00002360| 0a 42 65 6c 6f 77 20 69 | 73 20 61 6e 20 6f 75 74 |.Below i|s an out|
|00002370| 6c 69 6e 65 20 6f 66 20 | 74 68 65 20 66 69 6c 65 |line of |the file|
|00002380| 73 20 73 74 72 75 63 74 | 75 72 65 20 72 65 71 75 |s struct|ure requ|
|00002390| 69 72 65 64 20 66 6f 72 | 20 73 74 61 74 69 63 61 |ired for| statica|
|000023a0| 6c 6c 79 0a 6c 69 6e 6b | 69 6e 67 20 53 57 49 2d |lly.link|ing SWI-|
|000023b0| 50 72 6f 6c 6f 67 20 77 | 69 74 68 20 66 6f 72 65 |Prolog w|ith fore|
|000023c0| 69 67 6e 20 65 78 74 65 | 6e 73 69 6f 6e 73 2e 20 |ign exte|nsions. |
|000023d0| 5c 66 69 6c 65 7b 5c 6c | 64 6f 74 73 2f 70 6c 7d |\file{\l|dots/pl}|
|000023e0| 20 72 65 66 65 72 73 20 | 74 6f 20 74 68 65 0a 53 | refers |to the.S|
|000023f0| 57 49 2d 50 72 6f 6c 6f | 67 20 68 6f 6d 65 20 64 |WI-Prolo|g home d|
|00002400| 69 72 65 63 74 6f 72 79 | 20 28 73 65 65 20 66 65 |irectory| (see fe|
|00002410| 61 74 75 72 65 2f 32 29 | 2e 20 5c 66 69 6c 65 7b |ature/2)|. \file{|
|00002420| 3c 61 72 63 68 3e 7d 20 | 72 65 66 65 72 73 20 74 |<arch>} |refers t|
|00002430| 6f 20 74 68 65 0a 61 72 | 63 68 69 74 65 63 74 75 |o the.ar|chitectu|
|00002440| 72 65 20 69 64 65 6e 74 | 69 66 69 65 72 20 74 68 |re ident|ifier th|
|00002450| 61 74 20 6d 61 79 20 62 | 65 20 6f 62 74 61 69 6e |at may b|e obtain|
|00002460| 65 64 20 75 73 69 6e 67 | 20 66 65 61 74 75 72 65 |ed using| feature|
|00002470| 2f 32 2e 0a 0a 5c 62 65 | 67 69 6e 7b 63 65 6e 74 |/2...\be|gin{cent|
|00002480| 65 72 7d 0a 5c 62 65 67 | 69 6e 7b 74 61 62 75 6c |er}.\beg|in{tabul|
|00002490| 61 72 7d 7b 6c 6c 7d 0a | 5c 66 69 6c 65 7b 5c 6c |ar}{ll}.|\file{\l|
|000024a0| 64 6f 74 73 2f 70 6c 2f | 72 75 6e 74 69 6d 65 2f |dots/pl/|runtime/|
|000024b0| 3c 61 72 63 68 3e 2f 6c | 69 62 70 6c 2e 61 7d 20 |<arch>/l|ibpl.a} |
|000024c0| 20 20 20 26 20 53 57 49 | 2d 4c 69 62 72 61 72 79 | & SWI|-Library|
|000024d0| 20 5c 5c 0a 5c 66 69 6c | 65 7b 5c 6c 64 6f 74 73 | \\.\fil|e{\ldots|
|000024e0| 2f 70 6c 2f 69 6e 63 6c | 75 64 65 2f 53 57 49 2d |/pl/incl|ude/SWI-|
|000024f0| 50 72 6f 6c 6f 67 2e 68 | 7d 20 20 20 20 20 20 26 |Prolog.h|} &|
|00002500| 20 49 6e 63 6c 75 64 65 | 20 66 69 6c 65 20 5c 5c | Include| file \\|
|00002510| 0a 5c 66 69 6c 65 7b 5c | 6c 64 6f 74 73 2f 70 6c |.\file{\|ldots/pl|
|00002520| 2f 69 6e 63 6c 75 64 65 | 2f 53 57 49 2d 53 74 72 |/include|/SWI-Str|
|00002530| 65 61 6d 2e 68 7d 20 20 | 20 20 20 20 26 20 53 74 |eam.h} | & St|
|00002540| 72 65 61 6d 20 49 2f 4f | 20 69 6e 63 6c 75 64 65 |ream I/O| include|
|00002550| 20 66 69 6c 65 20 5c 5c | 0a 5c 66 69 6c 65 7b 5c | file \\|.\file{\|
|00002560| 6c 64 6f 74 73 2f 70 6c | 2f 69 6e 63 6c 75 64 65 |ldots/pl|/include|
|00002570| 2f 53 57 49 2d 45 78 70 | 6f 72 74 73 7d 20 20 20 |/SWI-Exp|orts} |
|00002580| 20 20 20 20 26 20 45 78 | 70 6f 72 74 20 64 65 63 | & Ex|port dec|
|00002590| 6c 61 72 61 74 69 6f 6e | 73 20 28 41 49 58 20 6f |laration|s (AIX o|
|000025a0| 6e 6c 79 29 20 5c 5c 0a | 5c 66 69 6c 65 7b 5c 6c |nly) \\.|\file{\l|
|000025b0| 64 6f 74 73 2f 70 6c 2f | 69 6e 63 6c 75 64 65 2f |dots/pl/|include/|
|000025c0| 73 74 75 62 2e 63 7d 20 | 20 20 20 20 20 20 20 20 |stub.c} | |
|000025d0| 20 20 20 26 20 45 78 74 | 65 6e 73 69 6f 6e 20 73 | & Ext|ension s|
|000025e0| 74 75 62 20 0a 5c 65 6e | 64 7b 74 61 62 75 6c 61 |tub .\en|d{tabula|
|000025f0| 72 7d 0a 5c 65 6e 64 7b | 63 65 6e 74 65 72 7d 0a |r}.\end{|center}.|
|00002600| 0a 54 68 65 20 64 65 66 | 69 6e 69 74 69 6f 6e 20 |.The def|inition |
|00002610| 6f 66 20 74 68 65 20 66 | 6f 72 65 69 67 6e 20 70 |of the f|oreign p|
|00002620| 72 65 64 69 63 61 74 65 | 73 20 69 73 20 74 68 65 |redicate|s is the|
|00002630| 20 73 61 6d 65 20 61 73 | 20 66 6f 72 20 64 79 6e | same as| for dyn|
|00002640| 61 6d 69 63 0a 6c 69 6e | 6b 69 6e 67 2e 20 20 55 |amic.lin|king. U|
|00002650| 6e 6c 69 6b 65 20 77 69 | 74 68 20 64 79 6e 61 6d |nlike wi|th dynam|
|00002660| 69 63 20 6c 69 6e 6b 69 | 6e 67 20 68 6f 77 65 76 |ic linki|ng howev|
|00002670| 65 72 2c 20 74 68 65 72 | 65 20 69 73 20 6e 6f 0a |er, ther|e is no.|
|00002680| 69 6e 69 74 69 61 6c 69 | 73 61 74 69 6f 6e 20 66 |initiali|sation f|
|00002690| 75 6e 63 74 69 6f 6e 2e | 20 20 49 6e 73 74 65 61 |unction.| Instea|
|000026a0| 64 2c 20 74 68 65 20 66 | 69 6c 65 20 5c 66 69 6c |d, the f|ile \fil|
|000026b0| 65 7b 5c 6c 64 6f 74 73 | 2f 70 6c 2f 69 6e 63 6c |e{\ldots|/pl/incl|
|000026c0| 75 64 65 2f 73 74 75 62 | 2e 63 7d 0a 6d 61 79 20 |ude/stub|.c}.may |
|000026d0| 62 65 20 63 6f 70 69 65 | 64 20 74 6f 20 79 6f 75 |be copie|d to you|
|000026e0| 72 20 70 72 6f 6a 65 63 | 74 20 61 6e 64 20 6d 6f |r projec|t and mo|
|000026f0| 64 69 66 69 65 64 20 74 | 6f 20 64 65 66 69 6e 65 |dified t|o define|
|00002700| 20 74 68 65 20 66 6f 72 | 65 69 67 6e 0a 65 78 74 | the for|eign.ext|
|00002710| 65 6e 73 69 6f 6e 73 2e | 20 20 42 65 6c 6f 77 20 |ensions.| Below |
|00002720| 69 73 20 73 74 75 62 2e | 63 2c 20 6d 6f 64 69 66 |is stub.|c, modif|
|00002730| 69 65 64 20 74 6f 20 6c | 69 6e 6b 20 74 68 65 20 |ied to l|ink the |
|00002740| 6c 6f 77 65 72 63 61 73 | 65 20 65 78 61 6d 70 6c |lowercas|e exampl|
|00002750| 65 0a 64 65 73 63 72 69 | 62 65 64 20 6c 61 74 65 |e.descri|bed late|
|00002760| 72 20 69 6e 20 74 68 69 | 73 20 63 68 61 70 74 65 |r in thi|s chapte|
|00002770| 72 3a 0a 0a 5c 62 65 67 | 69 6e 7b 63 6f 64 65 7d |r:..\beg|in{code}|
|00002780| 0a 2f 2a 20 20 43 6f 70 | 79 72 69 67 68 74 20 28 |./* Cop|yright (|
|00002790| 63 29 20 31 39 39 31 20 | 4a 61 6e 20 57 69 65 6c |c) 1991 |Jan Wiel|
|000027a0| 65 6d 61 6b 65 72 2e 20 | 41 6c 6c 20 72 69 67 68 |emaker. |All righ|
|000027b0| 74 73 20 72 65 73 65 72 | 76 65 64 2e 0a 20 20 20 |ts reser|ved.. |
|000027c0| 20 6a 61 6e 40 73 77 69 | 2e 70 73 79 2e 75 76 61 | jan@swi|.psy.uva|
|000027d0| 2e 6e 6c 0a 0a 20 20 20 | 20 50 75 72 70 6f 73 65 |.nl.. | Purpose|
|000027e0| 3a 20 53 6b 65 6c 65 74 | 6f 6e 20 66 6f 72 20 65 |: Skelet|on for e|
|000027f0| 78 74 65 6e 73 69 6f 6e | 73 0a 2a 2f 0a 0a 23 69 |xtension|s.*/..#i|
|00002800| 6e 63 6c 75 64 65 20 3c | 73 74 64 69 6f 2e 68 3e |nclude <|stdio.h>|
|00002810| 0a 23 69 6e 63 6c 75 64 | 65 20 3c 53 57 49 2d 50 |.#includ|e <SWI-P|
|00002820| 72 6f 6c 6f 67 2e 68 3e | 0a 0a 65 78 74 65 72 6e |rolog.h>|..extern|
|00002830| 20 66 6f 72 65 69 67 6e | 5f 74 20 70 6c 5f 6c 6f | foreign|_t pl_lo|
|00002840| 77 65 72 63 61 73 65 28 | 74 65 72 6d 2c 20 74 65 |wercase(|term, te|
|00002850| 72 6d 29 3b 0a 0a 50 4c | 5f 65 78 74 65 6e 73 69 |rm);..PL|_extensi|
|00002860| 6f 6e 20 70 72 65 64 69 | 63 61 74 65 73 5b 5d 20 |on predi|cates[] |
|00002870| 3d 0a 7b 0a 2f 2a 7b 20 | 22 6e 61 6d 65 22 2c 20 |=.{./*{ |"name", |
|00002880| 20 20 20 20 20 61 72 69 | 74 79 2c 20 20 66 75 6e | ari|ty, fun|
|00002890| 63 74 69 6f 6e 2c 20 20 | 20 20 20 20 50 4c 5f 46 |ction, | PL_F|
|000028a0| 41 5f 3c 66 6c 61 67 73 | 3e 20 7d 2c 2a 2f 0a 0a |A_<flags|> },*/..|
|000028b0| 20 20 7b 20 22 6c 6f 77 | 65 72 63 61 73 65 22 2c | { "low|ercase",|
|000028c0| 20 32 20 20 20 20 20 20 | 20 70 6c 5f 6c 6f 77 65 | 2 | pl_lowe|
|000028d0| 72 63 61 73 65 2c 20 20 | 30 20 7d 2c 0a 20 20 7b |rcase, |0 },. {|
|000028e0| 20 4e 55 4c 4c 2c 20 20 | 20 20 20 20 20 20 30 2c | NULL, | 0,|
|000028f0| 20 20 20 20 20 20 4e 55 | 4c 4c 2c 20 20 20 20 20 | NU|LL, |
|00002900| 20 20 20 20 20 30 20 7d | 20 20 20 20 20 2f 2a 20 | 0 }| /* |
|00002910| 74 65 72 6d 69 6e 61 74 | 69 6e 67 20 6c 69 6e 65 |terminat|ing line|
|00002920| 20 2a 2f 0a 7d 3b 0a 0a | 0a 69 6e 74 0a 6d 61 69 | */.};..|.int.mai|
|00002930| 6e 28 69 6e 74 20 61 72 | 67 63 2c 20 63 68 61 72 |n(int ar|gc, char|
|00002940| 20 2a 2a 61 72 67 76 29 | 0a 7b 20 50 4c 5f 72 65 | **argv)|.{ PL_re|
|00002950| 67 69 73 74 65 72 5f 65 | 78 74 65 6e 73 69 6f 6e |gister_e|xtension|
|00002960| 73 28 70 72 65 64 69 63 | 61 74 65 73 29 3b 0a 0a |s(predic|ates);..|
|00002970| 20 20 69 66 20 28 20 21 | 50 4c 5f 69 6e 69 74 69 | if ( !|PL_initi|
|00002980| 61 6c 69 73 65 28 61 72 | 67 63 2c 20 61 72 67 76 |alise(ar|gc, argv|
|00002990| 29 20 29 0a 20 20 20 20 | 50 4c 5f 68 61 6c 74 28 |) ). |PL_halt(|
|000029a0| 31 29 3b 0a 0a 20 20 50 | 4c 5f 69 6e 73 74 61 6c |1);.. P|L_instal|
|000029b0| 6c 5f 72 65 61 64 6c 69 | 6e 65 28 29 3b 20 20 20 |l_readli|ne(); |
|000029c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 2f 2a 20 | | /* |
|000029d0| 64 65 6c 65 74 65 20 69 | 66 20 6e 6f 74 20 72 65 |delete i|f not re|
|000029e0| 71 75 69 72 65 64 20 2a | 2f 0a 0a 20 20 50 4c 5f |quired *|/.. PL_|
|000029f0| 68 61 6c 74 28 50 4c 5f | 74 6f 70 6c 65 76 65 6c |halt(PL_|toplevel|
|00002a00| 28 29 20 3f 20 30 20 3a | 20 31 29 3b 0a 7d 0a 5c |() ? 0 :| 1);.}.\|
|00002a10| 65 6e 64 7b 63 6f 64 65 | 7d 0a 0a 4e 6f 77 2c 20 |end{code|}..Now, |
|00002a20| 61 20 6e 65 77 20 65 78 | 65 63 75 74 61 62 6c 65 |a new ex|ecutable|
|00002a30| 20 6d 61 79 20 62 65 20 | 63 72 65 61 74 65 64 20 | may be |created |
|00002a40| 62 79 20 63 6f 6d 70 69 | 6c 69 6e 67 20 74 68 69 |by compi|ling thi|
|00002a50| 73 20 66 69 6c 65 20 61 | 6e 64 20 6c 69 6e 6b 69 |s file a|nd linki|
|00002a60| 6e 67 0a 69 74 20 74 6f | 20 6c 69 62 70 6c 2e 61 |ng.it to| libpl.a|
|00002a70| 20 66 72 6f 6d 20 74 68 | 65 20 72 75 6e 74 69 6d | from th|e runtim|
|00002a80| 65 20 64 69 72 65 63 74 | 6f 72 79 20 61 6e 64 20 |e direct|ory and |
|00002a90| 74 68 65 20 6c 69 62 72 | 61 72 69 65 73 20 72 65 |the libr|aries re|
|00002aa0| 71 75 69 72 65 64 20 62 | 79 0a 62 6f 74 68 20 74 |quired b|y.both t|
|00002ab0| 68 65 20 65 78 74 65 6e | 73 69 6f 6e 73 20 61 6e |he exten|sions an|
|00002ac0| 64 20 74 68 65 20 53 57 | 49 2d 50 72 6f 6c 6f 67 |d the SW|I-Prolog|
|00002ad0| 20 6b 65 72 6e 65 6c 2e | 20 54 68 69 73 20 6d 61 | kernel.| This ma|
|00002ae0| 79 20 62 65 20 64 6f 6e | 65 20 62 79 20 68 61 6e |y be don|e by han|
|00002af0| 64 2c 0a 6f 72 20 75 73 | 69 6e 67 20 74 68 65 20 |d,.or us|ing the |
|00002b00| 5c 70 72 6f 67 72 61 6d | 7b 70 6c 6c 64 7d 20 75 |\program|{plld} u|
|00002b10| 74 69 6c 69 74 79 20 64 | 65 73 63 72 69 62 65 64 |tility d|escribed|
|00002b20| 20 69 6e 20 73 65 63 72 | 65 66 7b 70 6c 6c 64 7d | in secr|ef{plld}|
|00002b30| 2e 0a 0a 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |....\sub|section{|
|00002b40| 44 79 6e 61 6d 69 63 20 | 4c 69 6e 6b 69 6e 67 20 |Dynamic |Linking |
|00002b50| 62 61 73 65 64 20 6f 6e | 20 6c 6f 61 64 5f 66 6f |based on| load_fo|
|00002b60| 72 65 69 67 6e 2f 5b 32 | 2c 35 5d 7d 0a 0a 54 68 |reign/[2|,5]}..Th|
|00002b70| 65 20 70 72 65 64 69 63 | 61 74 65 73 20 62 65 6c |e predic|ates bel|
|00002b80| 6f 77 20 61 72 65 20 63 | 6f 6e 73 69 64 65 72 65 |ow are c|onsidere|
|00002b90| 64 20 6f 62 73 6f 6c 65 | 74 65 2e 20 54 68 65 79 |d obsole|te. They|
|00002ba0| 20 61 72 65 20 62 72 69 | 65 66 6c 79 20 64 65 73 | are bri|efly des|
|00002bb0| 63 72 69 62 65 64 0a 68 | 65 72 65 20 66 6f 72 20 |cribed.h|ere for |
|00002bc0| 63 6f 6d 70 61 74 69 62 | 69 6c 69 74 79 20 70 75 |compatib|ility pu|
|00002bd0| 72 70 6f 73 65 73 2e 20 | 20 4e 65 77 20 63 6f 64 |rposes. | New cod|
|00002be0| 65 20 73 68 6f 75 6c 64 | 20 75 73 65 20 74 68 65 |e should| use the|
|00002bf0| 20 70 72 65 64 69 63 61 | 74 65 73 0a 66 72 6f 6d | predica|tes.from|
|00002c00| 20 74 68 65 20 5c 66 69 | 6c 65 7b 6c 69 62 72 61 | the \fi|le{libra|
|00002c10| 72 79 28 73 68 6c 69 62 | 29 7d 2e 0a 0a 5c 62 65 |ry(shlib|)}...\be|
|00002c20| 67 69 6e 7b 64 65 73 63 | 72 69 70 74 69 6f 6e 7d |gin{desc|ription}|
|00002c30| 0a 5c 70 72 65 64 69 63 | 61 74 65 7b 6c 6f 61 64 |.\predic|ate{load|
|00002c40| 5f 66 6f 72 65 69 67 6e | 7d 7b 32 7d 7b 2b 46 69 |_foreign|}{2}{+Fi|
|00002c50| 6c 65 2c 20 2b 45 6e 74 | 72 79 7d 0a 4c 6f 61 64 |le, +Ent|ry}.Load|
|00002c60| 20 61 20 66 6f 72 65 69 | 67 6e 20 66 69 6c 65 20 | a forei|gn file |
|00002c70| 6f 72 20 6c 69 73 74 20 | 6f 66 20 66 69 6c 65 73 |or list |of files|
|00002c80| 20 73 70 65 63 69 66 69 | 65 64 20 62 79 20 5c 61 | specifi|ed by \a|
|00002c90| 72 67 7b 46 69 6c 65 7d | 2e 20 20 54 68 65 20 66 |rg{File}|. The f|
|00002ca0| 69 6c 65 73 0a 61 72 65 | 20 73 65 61 72 63 68 65 |iles.are| searche|
|00002cb0| 64 20 66 6f 72 20 73 69 | 6d 69 6c 61 72 20 74 6f |d for si|milar to|
|00002cc0| 20 63 6f 6e 73 75 6c 74 | 2f 31 2e 20 20 45 78 63 | consult|/1. Exc|
|00002cd0| 65 70 74 20 74 68 61 74 | 20 74 68 65 20 60 5c 66 |ept that| the `\f|
|00002ce0| 69 6c 65 65 78 74 7b 6f | 7d 27 0a 65 78 74 65 6e |ileext{o|}'.exten|
|00002cf0| 73 69 6f 6e 20 69 73 20 | 75 73 65 64 20 72 61 74 |sion is |used rat|
|00002d00| 68 65 72 20 74 68 61 6e | 20 60 5c 66 69 6c 65 65 |her than| `\filee|
|00002d10| 78 74 7b 70 6c 7d 27 2e | 0a 0a 5c 61 72 67 7b 45 |xt{pl}'.|..\arg{E|
|00002d20| 6e 74 72 79 7d 20 64 65 | 66 69 6e 65 73 20 74 68 |ntry} de|fines th|
|00002d30| 65 20 65 6e 74 72 79 20 | 70 6f 69 6e 74 20 6f 66 |e entry |point of|
|00002d40| 20 74 68 65 20 72 65 73 | 75 6c 74 69 6e 67 20 65 | the res|ulting e|
|00002d50| 78 65 63 75 74 61 62 6c | 65 2e 20 20 54 68 65 0a |xecutabl|e. The.|
|00002d60| 65 6e 74 72 79 20 70 6f | 69 6e 74 20 77 69 6c 6c |entry po|int will|
|00002d70| 20 62 65 20 63 61 6c 6c | 65 64 20 62 79 20 50 72 | be call|ed by Pr|
|00002d80| 6f 6c 6f 67 20 74 6f 20 | 69 6e 73 74 61 6c 6c 20 |olog to |install |
|00002d90| 74 68 65 20 66 6f 72 65 | 69 67 6e 20 70 72 65 64 |the fore|ign pred|
|00002da0| 69 63 61 74 65 73 2e 0a | 5c 70 72 65 64 69 63 61 |icates..|\predica|
|00002db0| 74 65 7b 6c 6f 61 64 5f | 66 6f 72 65 69 67 6e 7d |te{load_|foreign}|
|00002dc0| 7b 32 7d 7b 2b 46 69 6c | 65 2c 20 2b 45 6e 74 72 |{2}{+Fil|e, +Entr|
|00002dd0| 79 2c 20 2b 4f 70 74 69 | 6f 6e 73 2c 20 2b 4c 69 |y, +Opti|ons, +Li|
|00002de0| 62 72 61 72 69 65 73 2c | 20 2b 53 69 7a 65 7d 0a |braries,| +Size}.|
|00002df0| 54 68 65 20 66 69 72 73 | 74 20 74 77 6f 20 61 72 |The firs|t two ar|
|00002e00| 67 75 6d 65 6e 74 73 20 | 61 72 65 20 69 64 65 6e |guments |are iden|
|00002e10| 74 69 63 61 6c 20 74 6f | 20 74 68 6f 73 65 20 6f |tical to| those o|
|00002e20| 66 20 6c 6f 61 64 5f 66 | 6f 72 65 69 67 6e 2f 32 |f load_f|oreign/2|
|00002e30| 2e 20 7b 5c 65 6d 0a 4f | 70 74 69 6f 6e 73 7d 20 |. {\em.O|ptions} |
|00002e40| 69 73 20 28 61 20 6c 69 | 73 74 20 6f 66 29 20 61 |is (a li|st of) a|
|00002e50| 64 64 69 74 69 6f 6e 61 | 6c 20 6f 70 74 69 6f 6e |dditiona|l option|
|00002e60| 20 74 6f 20 62 65 20 67 | 69 76 65 6e 20 74 6f 20 | to be g|iven to |
|00002e70| 74 68 65 20 6c 6f 61 64 | 65 72 2e 0a 54 68 65 20 |the load|er..The |
|00002e80| 6f 70 74 69 6f 6e 73 20 | 61 72 65 20 69 6e 73 65 |options |are inse|
|00002e90| 72 74 65 64 20 6a 75 73 | 74 20 62 65 66 6f 72 65 |rted jus|t before|
|00002ea0| 20 74 68 65 20 66 69 6c | 65 73 2e 20 5c 61 72 67 | the fil|es. \arg|
|00002eb0| 7b 4c 69 62 72 61 72 69 | 65 73 7d 20 69 73 20 28 |{Librari|es} is (|
|00002ec0| 61 0a 6c 69 73 74 20 6f | 66 29 20 6c 69 62 72 61 |a.list o|f) libra|
|00002ed0| 72 69 65 73 20 74 6f 20 | 62 65 20 70 61 73 73 65 |ries to |be passe|
|00002ee0| 64 20 74 6f 20 74 68 65 | 20 6c 6f 61 64 65 72 2e |d to the| loader.|
|00002ef0| 20 54 68 65 79 20 61 72 | 65 20 69 6e 73 65 72 74 | They ar|e insert|
|00002f00| 65 64 20 6a 75 73 74 0a | 61 66 74 65 72 20 74 68 |ed just.|after th|
|00002f10| 65 20 66 69 6c 65 73 2e | 20 49 66 20 5c 61 72 67 |e files.| If \arg|
|00002f20| 7b 53 69 7a 65 7d 20 69 | 73 20 73 70 65 63 69 66 |{Size} i|s specif|
|00002f30| 69 65 64 20 50 72 6f 6c | 6f 67 20 66 69 72 73 74 |ied Prol|og first|
|00002f40| 20 61 73 73 75 6d 65 73 | 20 74 68 61 74 0a 74 68 | assumes| that.th|
|00002f50| 65 20 72 65 73 75 6c 74 | 69 6e 67 20 65 78 65 63 |e result|ing exec|
|00002f60| 75 74 61 62 6c 65 20 77 | 69 6c 6c 20 66 69 74 20 |utable w|ill fit |
|00002f70| 69 6e 20 5c 61 72 67 7b | 53 69 7a 65 7d 20 62 79 |in \arg{|Size} by|
|00002f80| 74 65 73 20 61 6e 64 20 | 64 6f 20 74 68 65 20 6c |tes and |do the l|
|00002f90| 6f 61 64 69 6e 67 0a 69 | 6e 20 6f 6e 65 20 70 61 |oading.i|n one pa|
|00002fa0| 73 73 2e 0a 5c 70 72 65 | 64 69 63 61 74 65 7b 66 |ss..\pre|dicate{f|
|00002fb0| 6f 72 65 69 67 6e 5f 66 | 69 6c 65 7d 7b 31 7d 7b |oreign_f|ile}{1}{|
|00002fc0| 3f 46 69 6c 65 7d 0a 49 | 73 20 74 72 75 65 20 69 |?File}.I|s true i|
|00002fd0| 66 20 5c 61 72 67 7b 46 | 69 6c 65 7d 20 69 73 20 |f \arg{F|ile} is |
|00002fe0| 74 68 65 20 61 62 73 6f | 6c 75 74 65 20 70 61 74 |the abso|lute pat|
|00002ff0| 68 20 6e 61 6d 65 20 6f | 66 20 61 20 66 69 6c 65 |h name o|f a file|
|00003000| 20 6c 6f 61 64 65 64 20 | 61 73 0a 66 6f 72 65 69 | loaded |as.forei|
|00003010| 67 6e 20 66 69 6c 65 2e | 0a 5c 65 6e 64 7b 64 65 |gn file.|.\end{de|
|00003020| 73 63 72 69 70 74 69 6f | 6e 7d 0a 0a 5c 73 65 63 |scriptio|n}..\sec|
|00003030| 74 69 6f 6e 7b 49 6e 74 | 65 72 66 61 63 65 20 44 |tion{Int|erface D|
|00003040| 61 74 61 20 74 79 70 65 | 73 7d 0a 0a 5c 73 75 62 |ata type|s}..\sub|
|00003050| 73 65 63 74 69 6f 6e 7b | 54 79 70 65 20 5c 63 74 |section{|Type \ct|
|00003060| 79 70 65 7b 74 65 72 6d | 5f 74 7d 3a 20 61 20 72 |ype{term|_t}: a r|
|00003070| 65 66 65 72 65 6e 63 65 | 20 74 6f 20 61 20 50 72 |eference| to a Pr|
|00003080| 6f 6c 6f 67 20 74 65 72 | 6d 7d 0a 0a 54 68 65 20 |olog ter|m}..The |
|00003090| 70 72 69 6e 63 69 70 61 | 6c 20 64 61 74 61 2d 74 |principa|l data-t|
|000030a0| 79 70 65 20 69 73 20 5c | 63 74 79 70 65 7b 74 65 |ype is \|ctype{te|
|000030b0| 72 6d 5f 74 7d 2e 20 54 | 79 70 65 20 5c 63 74 79 |rm_t}. T|ype \cty|
|000030c0| 70 65 7b 74 65 72 6d 5f | 74 7d 20 69 73 20 77 68 |pe{term_|t} is wh|
|000030d0| 61 74 0a 51 75 69 6e 74 | 75 73 20 63 61 6c 6c 73 |at.Quint|us calls|
|000030e0| 20 5c 63 74 79 70 65 7b | 51 50 5f 74 65 72 6d 5f | \ctype{|QP_term_|
|000030f0| 72 65 66 7d 2e 20 54 68 | 69 73 20 6e 61 6d 65 20 |ref}. Th|is name |
|00003100| 69 6e 64 69 63 61 74 65 | 73 20 62 65 74 74 65 72 |indicate|s better|
|00003110| 20 77 68 61 74 20 74 68 | 65 0a 74 79 70 65 20 72 | what th|e.type r|
|00003120| 65 70 72 65 73 65 6e 74 | 73 3a 20 69 74 20 69 73 |epresent|s: it is|
|00003130| 20 61 20 5c 6a 61 72 67 | 6f 6e 7b 68 61 6e 64 6c | a \jarg|on{handl|
|00003140| 65 7d 20 66 6f 72 20 61 | 20 74 65 72 6d 20 72 61 |e} for a| term ra|
|00003150| 74 68 65 72 20 74 68 61 | 6e 20 74 68 65 20 74 65 |ther tha|n the te|
|00003160| 72 6d 0a 69 74 73 65 6c | 66 2e 20 54 65 72 6d 73 |rm.itsel|f. Terms|
|00003170| 20 63 61 6e 20 6f 6e 6c | 79 20 62 65 20 72 65 70 | can onl|y be rep|
|00003180| 72 65 73 65 6e 74 65 64 | 20 61 6e 64 20 6d 61 6e |resented| and man|
|00003190| 69 70 75 6c 61 74 65 64 | 20 75 73 69 6e 67 20 74 |ipulated| using t|
|000031a0| 68 69 73 20 74 79 70 65 | 2c 0a 61 73 20 74 68 69 |his type|,.as thi|
|000031b0| 73 20 69 73 20 74 68 65 | 20 6f 6e 6c 79 20 73 61 |s is the| only sa|
|000031c0| 66 65 20 77 61 79 20 74 | 6f 20 65 6e 73 75 72 65 |fe way t|o ensure|
|000031d0| 20 74 68 65 20 50 72 6f | 6c 6f 67 20 6b 65 72 6e | the Pro|log kern|
|000031e0| 65 6c 20 69 73 20 61 77 | 61 72 65 20 6f 66 20 61 |el is aw|are of a|
|000031f0| 6c 6c 0a 74 65 72 6d 73 | 20 72 65 66 65 72 65 6e |ll.terms| referen|
|00003200| 63 65 64 20 62 79 20 66 | 6f 72 65 69 67 6e 20 63 |ced by f|oreign c|
|00003210| 6f 64 65 20 61 6e 64 20 | 74 68 75 73 20 61 6c 6c |ode and |thus all|
|00003220| 6f 77 73 20 74 68 65 20 | 6b 65 72 6e 65 6c 20 74 |ows the |kernel t|
|00003230| 6f 20 70 65 72 66 6f 72 | 6d 0a 67 61 72 62 61 67 |o perfor|m.garbag|
|00003240| 65 2d 63 6f 6c 6c 65 63 | 74 69 6f 6e 20 61 6e 64 |e-collec|tion and|
|00003250| 2f 6f 72 20 73 74 61 63 | 6b 2d 73 68 69 66 74 73 |/or stac|k-shifts|
|00003260| 20 77 68 69 6c 65 20 66 | 6f 72 65 69 67 6e 20 63 | while f|oreign c|
|00003270| 6f 64 65 20 69 73 20 61 | 63 74 69 76 65 2c 0a 66 |ode is a|ctive,.f|
|00003280| 6f 72 20 65 78 61 6d 70 | 6c 65 20 64 75 72 69 6e |or examp|le durin|
|00003290| 67 20 61 20 63 61 6c 6c | 62 61 63 6b 20 66 72 6f |g a call|back fro|
|000032a0| 6d 20 43 2e 0a 0a 41 20 | 74 65 72 6d 20 72 65 66 |m C...A |term ref|
|000032b0| 65 72 65 6e 63 65 20 69 | 73 20 61 20 43 20 75 6e |erence i|s a C un|
|000032c0| 73 69 67 6e 65 64 20 6c | 6f 6e 67 2c 20 72 65 70 |signed l|ong, rep|
|000032d0| 72 65 73 65 6e 74 69 6e | 67 20 74 68 65 20 6f 66 |resentin|g the of|
|000032e0| 66 73 65 74 20 6f 66 20 | 61 0a 76 61 72 69 61 62 |fset of |a.variab|
|000032f0| 6c 65 20 6f 6e 20 74 68 | 65 20 50 72 6f 6c 6f 67 |le on th|e Prolog|
|00003300| 20 65 6e 76 69 72 6f 6e | 6d 65 6e 74 2d 73 74 61 | environ|ment-sta|
|00003310| 63 6b 2e 20 20 41 20 66 | 6f 72 65 69 67 6e 20 66 |ck. A f|oreign f|
|00003320| 75 6e 63 74 69 6f 6e 20 | 69 73 20 70 61 73 73 65 |unction |is passe|
|00003330| 64 0a 74 65 72 6d 20 72 | 65 66 65 72 65 6e 63 65 |d.term r|eference|
|00003340| 73 20 66 6f 72 20 74 68 | 65 20 70 72 65 64 69 63 |s for th|e predic|
|00003350| 61 74 65 2d 61 72 67 75 | 6d 65 6e 74 73 2c 20 6f |ate-argu|ments, o|
|00003360| 6e 65 20 66 6f 72 20 65 | 61 63 68 20 61 72 67 75 |ne for e|ach argu|
|00003370| 6d 65 6e 74 2e 20 20 49 | 66 0a 72 65 66 65 72 65 |ment. I|f.refere|
|00003380| 6e 63 65 73 20 66 6f 72 | 20 69 6e 74 65 72 6d 65 |nces for| interme|
|00003390| 64 69 61 74 65 20 72 65 | 73 75 6c 74 73 20 61 72 |diate re|sults ar|
|000033a0| 65 20 6e 65 65 64 65 64 | 2c 20 73 75 63 68 20 72 |e needed|, such r|
|000033b0| 65 66 65 72 65 6e 63 65 | 73 20 6d 61 79 20 62 65 |eference|s may be|
|000033c0| 0a 63 72 65 61 74 65 64 | 20 75 73 69 6e 67 20 50 |.created| using P|
|000033d0| 4c 5f 6e 65 77 5f 74 65 | 72 6d 5f 72 65 66 28 29 |L_new_te|rm_ref()|
|000033e0| 20 6f 72 20 50 4c 5f 6e | 65 77 5f 74 65 72 6d 5f | or PL_n|ew_term_|
|000033f0| 72 65 66 73 28 29 2e 20 | 20 54 68 65 73 65 20 72 |refs(). | These r|
|00003400| 65 66 65 72 65 6e 63 65 | 73 0a 6e 6f 72 6d 61 6c |eference|s.normal|
|00003410| 6c 79 20 6c 69 76 65 20 | 74 69 6c 6c 20 74 68 65 |ly live |till the|
|00003420| 20 66 6f 72 65 69 67 6e | 20 66 75 6e 63 74 69 6f | foreign| functio|
|00003430| 6e 20 72 65 74 75 72 6e | 73 20 63 6f 6e 74 72 6f |n return|s contro|
|00003440| 6c 20 62 61 63 6b 20 74 | 6f 20 50 72 6f 6c 6f 67 |l back t|o Prolog|
|00003450| 2e 0a 54 68 65 69 72 20 | 73 63 6f 70 65 20 63 61 |..Their |scope ca|
|00003460| 6e 20 62 65 20 65 78 70 | 6c 69 63 69 74 6c 79 20 |n be exp|licitly |
|00003470| 6c 69 6d 69 74 65 64 20 | 75 73 69 6e 67 20 50 4c |limited |using PL|
|00003480| 5f 6f 70 65 6e 5f 66 6f | 72 65 69 67 6e 5f 66 72 |_open_fo|reign_fr|
|00003490| 61 6d 65 28 29 0a 61 6e | 64 20 50 4c 5f 63 6c 6f |ame().an|d PL_clo|
|000034a0| 73 65 5f 66 6f 72 65 69 | 67 6e 5f 66 72 61 6d 65 |se_forei|gn_frame|
|000034b0| 28 29 2f 50 4c 5f 64 69 | 73 63 61 72 64 5f 66 6f |()/PL_di|scard_fo|
|000034c0| 72 65 69 67 6e 5f 66 72 | 61 6d 65 28 29 2e 0a 0a |reign_fr|ame()...|
|000034d0| 41 20 74 65 72 6d 5f 74 | 20 61 6c 77 61 79 73 20 |A term_t| always |
|000034e0| 72 65 66 65 72 73 20 74 | 6f 20 61 20 76 61 6c 69 |refers t|o a vali|
|000034f0| 64 20 50 72 6f 6c 6f 67 | 20 74 65 72 6d 20 28 76 |d Prolog| term (v|
|00003500| 61 72 69 61 62 6c 65 2c | 20 61 74 6f 6d 2c 20 69 |ariable,| atom, i|
|00003510| 6e 74 65 67 65 72 2c 0a | 66 6c 6f 61 74 20 6f 72 |nteger,.|float or|
|00003520| 20 63 6f 6d 70 6f 75 6e | 64 20 74 65 72 6d 29 2e | compoun|d term).|
|00003530| 20 41 20 74 65 72 6d 20 | 6c 69 76 65 73 20 65 69 | A term |lives ei|
|00003540| 74 68 65 72 20 75 6e 74 | 69 6c 20 62 61 63 6b 74 |ther unt|il backt|
|00003550| 72 61 63 6b 69 6e 67 20 | 74 61 6b 65 73 20 75 73 |racking |takes us|
|00003560| 0a 62 61 63 6b 20 74 6f | 20 61 20 70 6f 69 6e 74 |.back to| a point|
|00003570| 20 62 65 66 6f 72 65 20 | 74 68 65 20 74 65 72 6d | before |the term|
|00003580| 20 77 61 73 20 63 72 65 | 61 74 65 64 2c 20 74 68 | was cre|ated, th|
|00003590| 65 20 67 61 72 62 61 67 | 65 20 63 6f 6c 6c 65 63 |e garbag|e collec|
|000035a0| 74 6f 72 20 68 61 73 0a | 63 6f 6c 6c 65 63 74 65 |tor has.|collecte|
|000035b0| 64 20 74 68 65 20 74 65 | 72 6d 20 6f 72 20 74 68 |d the te|rm or th|
|000035c0| 65 20 74 65 72 6d 20 77 | 61 73 20 63 72 65 61 74 |e term w|as creat|
|000035d0| 65 64 20 61 66 74 65 72 | 20 61 0a 50 4c 5f 6f 70 |ed after| a.PL_op|
|000035e0| 65 6e 5f 66 6f 72 65 69 | 67 6e 5f 66 72 61 6d 65 |en_forei|gn_frame|
|000035f0| 28 29 20 61 6e 64 20 50 | 4c 5f 64 69 73 63 61 72 |() and P|L_discar|
|00003600| 64 5f 66 6f 72 65 69 67 | 6e 5f 66 72 61 6d 65 28 |d_foreig|n_frame(|
|00003610| 29 20 68 61 73 20 62 65 | 65 6e 20 63 61 6c 6c 65 |) has be|en calle|
|00003620| 64 2e 0a 0a 54 68 65 20 | 66 6f 72 65 69 67 6e 2d |d...The |foreign-|
|00003630| 69 6e 74 65 72 66 61 63 | 65 20 66 75 6e 63 74 69 |interfac|e functi|
|00003640| 6f 6e 73 20 63 61 6e 20 | 65 69 74 68 65 72 20 7b |ons can |either {|
|00003650| 5c 65 6d 20 72 65 61 64 | 7d 2c 20 7b 5c 65 6d 20 |\em read|}, {\em |
|00003660| 75 6e 69 66 79 7d 20 6f | 72 0a 7b 5c 65 6d 20 77 |unify} o|r.{\em w|
|00003670| 72 69 74 65 7d 20 74 6f | 20 74 65 72 6d 2d 72 65 |rite} to| term-re|
|00003680| 66 65 72 65 6e 63 65 73 | 2e 20 20 49 6e 20 74 68 |ferences|. In th|
|00003690| 65 20 74 68 69 73 20 64 | 6f 63 75 6d 65 6e 74 20 |e this d|ocument |
|000036a0| 77 65 20 75 73 65 20 74 | 68 65 0a 66 6f 6c 6c 6f |we use t|he.follo|
|000036b0| 77 69 6e 67 20 6e 6f 74 | 61 74 69 6f 6e 20 66 6f |wing not|ation fo|
|000036c0| 72 20 61 72 67 75 6d 65 | 6e 74 73 20 6f 66 20 74 |r argume|nts of t|
|000036d0| 79 70 65 20 74 65 72 6d | 5f 74 3a 0a 0a 5c 62 65 |ype term|_t:..\be|
|000036e0| 67 69 6e 7b 71 75 6f 74 | 65 7d 0a 5c 62 65 67 69 |gin{quot|e}.\begi|
|000036f0| 6e 7b 74 61 62 75 6c 61 | 72 7d 7b 6c 70 7b 33 2e |n{tabula|r}{lp{3.|
|00003700| 35 69 6e 7d 7d 0a 5c 74 | 74 20 74 65 72 6d 5f 74 |5in}}.\t|t term_t|
|00003710| 20 2b 74 20 20 20 26 20 | 41 63 63 65 73 73 65 64 | +t & |Accessed|
|00003720| 20 69 6e 20 72 65 61 64 | 2d 6d 6f 64 65 2e 20 20 | in read|-mode. |
|00003730| 54 68 65 20 60 2b 27 20 | 69 6e 64 69 63 61 74 65 |The `+' |indicate|
|00003740| 73 20 74 68 65 0a 20 20 | 20 20 20 20 20 20 20 20 |s the. | |
|00003750| 20 20 20 20 20 20 20 20 | 61 72 67 75 6d 65 6e 74 | |argument|
|00003760| 20 69 73 20 60 69 6e 70 | 75 74 27 2e 20 5c 5c 0a | is `inp|ut'. \\.|
|00003770| 5c 74 74 20 74 65 72 6d | 5f 74 20 2d 74 20 20 20 |\tt term|_t -t |
|00003780| 26 20 41 63 63 65 73 73 | 65 64 20 69 6e 20 77 72 |& Access|ed in wr|
|00003790| 69 74 65 2d 6d 6f 64 65 | 2e 20 5c 5c 0a 5c 74 74 |ite-mode|. \\.\tt|
|000037a0| 20 74 65 72 6d 5f 74 20 | 3f 74 20 20 20 26 20 41 | term_t |?t & A|
|000037b0| 63 63 65 73 73 65 64 20 | 69 6e 20 75 6e 69 66 79 |ccessed |in unify|
|000037c0| 2d 6d 6f 64 65 2e 20 5c | 5c 0a 5c 65 6e 64 7b 74 |-mode. \|\.\end{t|
|000037d0| 61 62 75 6c 61 72 7d 0a | 5c 65 6e 64 7b 71 75 6f |abular}.|\end{quo|
|000037e0| 74 65 7d 0a 0a 5c 6e 6f | 69 6e 64 65 6e 74 0a 54 |te}..\no|indent.T|
|000037f0| 65 72 6d 20 72 65 66 65 | 72 65 6e 63 65 73 20 61 |erm refe|rences a|
|00003800| 72 65 20 6f 62 74 61 69 | 6e 65 64 20 69 6e 20 61 |re obtai|ned in a|
|00003810| 6e 79 20 6f 66 20 74 68 | 65 20 66 6f 6c 6c 6f 77 |ny of th|e follow|
|00003820| 69 6e 67 20 77 61 79 73 | 2e 0a 0a 5c 62 65 67 69 |ing ways|...\begi|
|00003830| 6e 7b 69 74 65 6d 6c 69 | 73 74 7d 0a 5c 69 74 65 |n{itemli|st}.\ite|
|00003840| 6d 20 5b 50 61 73 73 65 | 64 20 61 73 20 61 72 67 |m [Passe|d as arg|
|00003850| 75 6d 65 6e 74 5d 0a 20 | 20 20 20 54 68 65 20 43 |ument]. | The C|
|00003860| 2d 66 75 6e 63 74 69 6f | 6e 73 20 69 6d 70 6c 65 |-functio|ns imple|
|00003870| 6d 65 6e 74 69 6e 67 20 | 66 6f 72 65 69 67 6e 20 |menting |foreign |
|00003880| 70 72 65 64 69 63 61 74 | 65 73 20 61 72 65 20 70 |predicat|es are p|
|00003890| 61 73 73 65 64 20 74 68 | 65 69 72 0a 20 20 20 20 |assed th|eir. |
|000038a0| 61 72 67 75 6d 65 6e 74 | 73 20 61 73 20 74 65 72 |argument|s as ter|
|000038b0| 6d 2d 72 65 66 65 72 65 | 6e 63 65 73 2e 20 20 54 |m-refere|nces. T|
|000038c0| 68 65 73 65 20 72 65 66 | 65 72 65 6e 63 65 73 20 |hese ref|erences |
|000038d0| 6d 61 79 20 62 65 20 72 | 65 61 64 20 6f 72 0a 20 |may be r|ead or. |
|000038e0| 20 20 20 75 6e 69 66 69 | 65 64 2e 20 20 57 72 69 | unifi|ed. Wri|
|000038f0| 74 69 6e 67 20 74 6f 20 | 74 68 65 73 65 20 76 61 |ting to |these va|
|00003900| 72 69 61 62 6c 65 73 20 | 63 61 75 73 65 73 20 75 |riables |causes u|
|00003910| 6e 64 65 66 69 6e 65 64 | 20 62 65 68 61 76 69 6f |ndefined| behavio|
|00003920| 75 72 2e 0a 5c 69 74 65 | 6d 20 5b 43 72 65 61 74 |ur..\ite|m [Creat|
|00003930| 65 64 20 62 79 20 50 4c | 5f 6e 65 77 5f 74 65 72 |ed by PL|_new_ter|
|00003940| 6d 5f 72 65 66 28 29 5d | 0a 20 20 20 20 41 20 74 |m_ref()]|. A t|
|00003950| 65 72 6d 20 63 72 65 61 | 74 65 64 20 62 79 20 50 |erm crea|ted by P|
|00003960| 4c 5f 6e 65 77 5f 74 65 | 72 6d 5f 72 65 66 28 29 |L_new_te|rm_ref()|
|00003970| 20 69 73 20 6e 6f 72 6d | 61 6c 6c 79 20 75 73 65 | is norm|ally use|
|00003980| 64 20 74 6f 20 62 75 69 | 6c 64 0a 20 20 20 20 74 |d to bui|ld. t|
|00003990| 65 6d 70 6f 72 61 72 79 | 20 74 65 72 6d 73 20 6f |emporary| terms o|
|000039a0| 72 20 62 65 20 77 72 69 | 74 74 65 6e 20 62 79 20 |r be wri|tten by |
|000039b0| 6f 6e 65 20 6f 66 20 74 | 68 65 20 69 6e 74 65 72 |one of t|he inter|
|000039c0| 66 61 63 65 20 66 75 6e | 63 74 69 6f 6e 73 2e 0a |face fun|ctions..|
|000039d0| 20 20 20 20 46 6f 72 20 | 65 78 61 6d 70 6c 65 2c | For |example,|
|000039e0| 20 50 4c 5f 67 65 74 5f | 61 72 67 28 29 20 77 72 | PL_get_|arg() wr|
|000039f0| 69 74 65 73 20 61 20 72 | 65 66 65 72 65 6e 63 65 |ites a r|eference|
|00003a00| 20 74 6f 20 74 68 65 20 | 74 65 72 6d 2d 61 72 67 | to the |term-arg|
|00003a10| 75 6d 65 6e 74 0a 20 20 | 20 20 69 6e 20 69 74 73 |ument. | in its|
|00003a20| 20 6c 61 73 74 20 61 72 | 67 75 6d 65 6e 74 2e 0a | last ar|gument..|
|00003a30| 5c 69 74 65 6d 20 5b 43 | 72 65 61 74 65 64 20 62 |\item [C|reated b|
|00003a40| 79 20 50 4c 5f 6e 65 77 | 5f 74 65 72 6d 5f 72 65 |y PL_new|_term_re|
|00003a50| 66 73 28 69 6e 74 20 6e | 29 5d 0a 20 20 20 20 54 |fs(int n|)]. T|
|00003a60| 68 69 73 20 66 75 6e 63 | 74 69 6f 6e 20 72 65 74 |his func|tion ret|
|00003a70| 75 72 6e 73 20 61 20 73 | 65 74 20 6f 66 20 74 65 |urns a s|et of te|
|00003a80| 72 6d 20 72 65 66 73 20 | 77 69 74 68 20 74 68 65 |rm refs |with the|
|00003a90| 20 73 61 6d 65 20 63 68 | 61 72 61 63 74 65 72 69 | same ch|aracteri|
|00003aa0| 73 74 69 63 73 0a 20 20 | 20 20 61 73 20 50 4c 5f |stics. | as PL_|
|00003ab0| 6e 65 77 5f 74 65 72 6d | 5f 72 65 66 28 29 2e 20 |new_term|_ref(). |
|00003ac0| 20 53 65 65 20 50 4c 5f | 6f 70 65 6e 5f 71 75 65 | See PL_|open_que|
|00003ad0| 72 79 28 29 2e 0a 5c 69 | 74 65 6d 20 5b 43 72 65 |ry()..\i|tem [Cre|
|00003ae0| 61 74 65 64 20 62 79 20 | 50 4c 5f 63 6f 70 79 5f |ated by |PL_copy_|
|00003af0| 74 65 72 6d 5f 72 65 66 | 28 74 65 72 6d 5f 74 20 |term_ref|(term_t |
|00003b00| 74 29 5d 0a 20 20 20 20 | 43 72 65 61 74 65 73 20 |t)]. |Creates |
|00003b10| 61 20 6e 65 77 20 74 65 | 72 6d 2d 72 65 66 65 72 |a new te|rm-refer|
|00003b20| 65 6e 63 65 20 74 6f 20 | 74 68 65 20 73 61 6d 65 |ence to |the same|
|00003b30| 20 74 65 72 6d 20 61 73 | 20 74 68 65 20 61 72 67 | term as| the arg|
|00003b40| 75 6d 65 6e 74 2e 20 20 | 54 68 65 0a 20 20 20 20 |ument. |The. |
|00003b50| 74 65 72 6d 20 6d 61 79 | 20 62 65 20 77 72 69 74 |term may| be writ|
|00003b60| 74 65 6e 20 74 6f 2e 20 | 20 53 65 65 20 5c 66 69 |ten to. | See \fi|
|00003b70| 67 72 65 66 7b 70 6c 2d | 64 69 73 70 6c 61 79 7d |gref{pl-|display}|
|00003b80| 2e 0a 5c 65 6e 64 7b 69 | 74 65 6d 6c 69 73 74 7d |..\end{i|temlist}|
|00003b90| 0a 0a 54 65 72 6d 2d 72 | 65 66 65 72 65 6e 63 65 |..Term-r|eference|
|00003ba0| 73 20 63 61 6e 20 73 61 | 66 65 6c 79 20 62 65 20 |s can sa|fely be |
|00003bb0| 63 6f 70 69 65 64 20 74 | 6f 20 6f 74 68 65 72 20 |copied t|o other |
|00003bc0| 43 2d 76 61 72 69 61 62 | 6c 65 73 20 6f 66 20 74 |C-variab|les of t|
|00003bd0| 79 70 65 0a 74 65 72 6d | 5f 74 2c 20 62 75 74 20 |ype.term|_t, but |
|00003be0| 61 6c 6c 20 63 6f 70 69 | 65 73 20 77 69 6c 6c 20 |all copi|es will |
|00003bf0| 61 6c 77 61 79 73 20 72 | 65 66 65 72 20 74 6f 20 |always r|efer to |
|00003c00| 74 68 65 20 73 61 6d 65 | 20 74 65 72 6d 2e 0a 0a |the same| term...|
|00003c10| 5c 62 65 67 69 6e 7b 64 | 65 73 63 72 69 70 74 69 |\begin{d|escripti|
|00003c20| 6f 6e 7d 0a 5c 63 66 75 | 6e 63 74 69 6f 6e 7b 74 |on}.\cfu|nction{t|
|00003c30| 65 72 6d 5f 74 7d 7b 50 | 4c 5f 6e 65 77 5f 74 65 |erm_t}{P|L_new_te|
|00003c40| 72 6d 5f 72 65 66 7d 7b | 7d 0a 52 65 74 75 72 6e |rm_ref}{|}.Return|
|00003c50| 20 61 20 66 72 65 73 68 | 20 72 65 66 65 72 65 6e | a fresh| referen|
|00003c60| 63 65 20 74 6f 20 61 20 | 74 65 72 6d 2e 20 20 54 |ce to a |term. T|
|00003c70| 68 65 20 72 65 66 65 72 | 65 6e 63 65 20 69 73 20 |he refer|ence is |
|00003c80| 61 6c 6c 6f 63 61 74 65 | 64 20 6f 6e 20 74 68 65 |allocate|d on the|
|00003c90| 0a 5c 6a 61 72 67 6f 6e | 7b 6c 6f 63 61 6c 7d 20 |.\jargon|{local} |
|00003ca0| 73 74 61 63 6b 2e 20 20 | 41 6c 6c 6f 63 61 74 69 |stack. |Allocati|
|00003cb0| 6e 67 20 61 20 74 65 72 | 6d 2d 72 65 66 65 72 65 |ng a ter|m-refere|
|00003cc0| 6e 63 65 20 6d 61 79 20 | 74 72 69 67 67 65 72 20 |nce may |trigger |
|00003cd0| 61 20 73 74 61 63 6b 2d | 73 68 69 66 74 0a 6f 6e |a stack-|shift.on|
|00003ce0| 20 6d 61 63 68 69 6e 65 | 73 20 74 68 61 74 20 63 | machine|s that c|
|00003cf0| 61 6e 6e 6f 74 20 75 73 | 65 20 73 70 61 72 73 65 |annot us|e sparse|
|00003d00| 2d 6d 65 6d 6f 72 79 20 | 6d 61 6e 61 67 65 6d 65 |-memory |manageme|
|00003d10| 6e 74 20 66 6f 72 20 61 | 6c 6c 6f 63 61 74 69 6f |nt for a|llocatio|
|00003d20| 6e 20 74 68 65 0a 50 72 | 6f 6c 6f 67 20 73 74 61 |n the.Pr|olog sta|
|00003d30| 63 6b 73 2e 20 20 54 68 | 65 20 72 65 74 75 72 6e |cks. Th|e return|
|00003d40| 65 64 20 72 65 66 65 72 | 65 6e 63 65 20 64 65 73 |ed refer|ence des|
|00003d50| 63 72 69 62 65 73 20 61 | 20 76 61 72 69 61 62 6c |cribes a| variabl|
|00003d60| 65 2e 0a 5c 63 66 75 6e | 63 74 69 6f 6e 7b 74 65 |e..\cfun|ction{te|
|00003d70| 72 6d 5f 74 7d 7b 50 4c | 5f 6e 65 77 5f 74 65 72 |rm_t}{PL|_new_ter|
|00003d80| 6d 5f 72 65 66 73 7d 7b | 69 6e 74 20 6e 7d 0a 52 |m_refs}{|int n}.R|
|00003d90| 65 74 75 72 6e 20 5c 61 | 72 67 7b 6e 7d 20 6e 65 |eturn \a|rg{n} ne|
|00003da0| 77 20 74 65 72 6d 20 72 | 65 66 65 72 65 6e 63 65 |w term r|eference|
|00003db0| 73 2e 20 20 54 68 65 20 | 66 69 72 73 74 20 74 65 |s. The |first te|
|00003dc0| 72 6d 2d 72 65 66 65 72 | 65 6e 63 65 20 69 73 20 |rm-refer|ence is |
|00003dd0| 72 65 74 75 72 6e 65 64 | 2e 0a 54 68 65 20 6f 74 |returned|..The ot|
|00003de0| 68 65 72 73 20 61 72 65 | 20 24 5c 61 72 67 7b 74 |hers are| $\arg{t|
|00003df0| 7d 2b 31 24 2c 20 24 5c | 61 72 67 7b 74 7d 2b 32 |}+1$, $\|arg{t}+2|
|00003e00| 24 2c 20 65 74 63 2e 20 | 20 54 68 65 72 65 20 61 |$, etc. | There a|
|00003e10| 72 65 20 74 77 6f 20 72 | 65 61 73 6f 6e 73 0a 66 |re two r|easons.f|
|00003e20| 6f 72 20 75 73 69 6e 67 | 20 74 68 69 73 20 66 75 |or using| this fu|
|00003e30| 6e 63 74 69 6f 6e 2e 20 | 20 50 4c 5f 6f 70 65 6e |nction. | PL_open|
|00003e40| 5f 71 75 65 72 79 28 29 | 20 65 78 70 65 63 74 73 |_query()| expects|
|00003e50| 20 74 68 65 20 61 72 67 | 75 6d 65 6e 74 73 20 61 | the arg|uments a|
|00003e60| 73 20 61 20 73 65 74 0a | 6f 66 20 63 6f 6e 73 65 |s a set.|of conse|
|00003e70| 63 75 74 69 76 65 20 74 | 65 72 6d 20 72 65 66 65 |cutive t|erm refe|
|00003e80| 72 65 6e 63 65 73 20 61 | 6e 64 20 7b 5c 65 6d 20 |rences a|nd {\em |
|00003e90| 76 65 72 79 7d 20 74 69 | 6d 65 2d 63 72 69 74 69 |very} ti|me-criti|
|00003ea0| 63 61 6c 20 63 6f 64 65 | 20 72 65 71 75 69 72 69 |cal code| requiri|
|00003eb0| 6e 67 0a 61 20 6e 75 6d | 62 65 72 20 6f 66 20 74 |ng.a num|ber of t|
|00003ec0| 65 72 6d 2d 72 65 66 65 | 72 65 6e 63 65 73 20 63 |erm-refe|rences c|
|00003ed0| 61 6e 20 62 65 20 77 72 | 69 74 74 65 6e 20 61 73 |an be wr|itten as|
|00003ee0| 3a 0a 0a 5c 62 65 67 69 | 6e 7b 63 6f 64 65 7d 0a |:..\begi|n{code}.|
|00003ef0| 70 6c 5f 6d 79 70 72 65 | 64 69 63 61 74 65 28 74 |pl_mypre|dicate(t|
|00003f00| 65 72 6d 5f 74 20 61 30 | 2c 20 74 65 72 6d 5f 74 |erm_t a0|, term_t|
|00003f10| 20 61 31 29 0a 7b 20 74 | 65 72 6d 5f 74 20 74 30 | a1).{ t|erm_t t0|
|00003f20| 20 3d 20 50 4c 5f 6e 65 | 77 5f 74 65 72 6d 5f 72 | = PL_ne|w_term_r|
|00003f30| 65 66 73 28 32 29 3b 0a | 20 20 74 65 72 6d 5f 74 |efs(2);.| term_t|
|00003f40| 20 74 31 20 3d 20 74 30 | 2b 31 3b 0a 0a 20 20 2e | t1 = t0|+1;.. .|
|00003f50| 2e 2e 0a 7d 0a 5c 65 6e | 64 7b 63 6f 64 65 7d 0a |...}.\en|d{code}.|
|00003f60| 5c 63 66 75 6e 63 74 69 | 6f 6e 7b 74 65 72 6d 5f |\cfuncti|on{term_|
|00003f70| 74 7d 7b 50 4c 5f 63 6f | 70 79 5f 74 65 72 6d 5f |t}{PL_co|py_term_|
|00003f80| 72 65 66 7d 7b 74 65 72 | 6d 5f 74 20 66 72 6f 6d |ref}{ter|m_t from|
|00003f90| 7d 0a 43 72 65 61 74 65 | 20 61 20 6e 65 77 20 74 |}.Create| a new t|
|00003fa0| 65 72 6d 20 72 65 66 65 | 72 65 6e 63 65 20 61 6e |erm refe|rence an|
|00003fb0| 64 20 6d 61 6b 65 20 69 | 74 20 70 6f 69 6e 74 20 |d make i|t point |
|00003fc0| 69 6e 69 74 69 61 6c 6c | 79 20 74 6f 20 74 68 65 |initiall|y to the|
|00003fd0| 20 73 61 6d 65 0a 74 65 | 72 6d 20 61 73 20 5c 61 | same.te|rm as \a|
|00003fe0| 72 67 7b 66 72 6f 6d 7d | 2e 20 20 54 68 69 73 20 |rg{from}|. This |
|00003ff0| 66 75 6e 63 74 69 6f 6e | 20 69 73 20 63 6f 6d 6d |function| is comm|
|00004000| 6f 6e 6c 79 20 75 73 65 | 64 20 74 6f 20 63 6f 70 |only use|d to cop|
|00004010| 79 20 61 20 70 72 65 64 | 69 63 61 74 65 0a 61 72 |y a pred|icate.ar|
|00004020| 67 75 6d 65 6e 74 20 74 | 6f 20 61 20 74 65 72 6d |gument t|o a term|
|00004030| 20 72 65 66 65 72 65 6e | 63 65 20 74 68 61 74 20 | referen|ce that |
|00004040| 6d 61 79 20 62 65 20 77 | 72 69 74 74 65 6e 2e 0a |may be w|ritten..|
|00004050| 5c 63 66 75 6e 63 74 69 | 6f 6e 7b 76 6f 69 64 7d |\cfuncti|on{void}|
|00004060| 7b 50 4c 5f 72 65 73 65 | 74 5f 74 65 72 6d 5f 72 |{PL_rese|t_term_r|
|00004070| 65 66 73 7d 7b 74 65 72 | 6d 5f 74 20 61 66 74 65 |efs}{ter|m_t afte|
|00004080| 72 7d 0a 44 65 73 74 72 | 6f 79 20 61 6c 6c 20 74 |r}.Destr|oy all t|
|00004090| 65 72 6d 20 72 65 66 65 | 72 65 6e 63 65 73 20 74 |erm refe|rences t|
|000040a0| 68 61 74 20 68 61 76 65 | 20 62 65 65 6e 20 63 72 |hat have| been cr|
|000040b0| 65 61 74 65 64 20 61 66 | 74 65 72 20 5c 61 72 67 |eated af|ter \arg|
|000040c0| 7b 61 66 74 65 72 7d 2c | 0a 69 6e 63 6c 75 64 69 |{after},|.includi|
|000040d0| 6e 67 20 5c 61 72 67 7b | 61 66 74 65 72 7d 20 69 |ng \arg{|after} i|
|000040e0| 74 73 65 6c 66 2e 20 41 | 6e 79 20 72 65 66 65 72 |tself. A|ny refer|
|000040f0| 65 6e 63 65 20 74 6f 20 | 74 68 65 20 69 6e 76 61 |ence to |the inva|
|00004100| 6c 69 64 61 74 65 64 20 | 20 74 65 72 6d 0a 72 65 |lidated | term.re|
|00004110| 66 65 72 65 6e 63 65 73 | 20 61 66 74 65 72 20 74 |ferences| after t|
|00004120| 68 69 73 20 63 61 6c 6c | 20 72 65 73 75 6c 74 73 |his call| results|
|00004130| 20 69 6e 20 75 6e 64 65 | 66 69 6e 65 64 20 62 65 | in unde|fined be|
|00004140| 68 61 76 69 6f 75 72 2e | 0a 0a 4e 6f 74 65 20 74 |haviour.|..Note t|
|00004150| 68 61 74 20 72 65 74 75 | 72 6e 69 6e 67 20 66 72 |hat retu|rning fr|
|00004160| 6f 6d 20 74 68 65 20 66 | 6f 72 65 69 67 6e 20 63 |om the f|oreign c|
|00004170| 6f 6e 74 65 78 74 20 74 | 6f 20 50 72 6f 6c 6f 67 |ontext t|o Prolog|
|00004180| 20 77 69 6c 6c 20 72 65 | 63 6c 61 69 6d 0a 61 6c | will re|claim.al|
|00004190| 6c 20 72 65 66 65 72 65 | 6e 63 65 73 20 75 73 65 |l refere|nces use|
|000041a0| 64 20 69 6e 20 74 68 65 | 20 66 6f 72 65 69 67 6e |d in the| foreign|
|000041b0| 20 63 6f 6e 74 65 78 74 | 2e 20 20 54 68 69 73 20 | context|. This |
|000041c0| 63 61 6c 6c 20 69 73 20 | 6f 6e 6c 79 20 6e 65 63 |call is |only nec|
|000041d0| 65 73 73 61 72 79 0a 69 | 66 20 72 65 66 65 72 65 |essary.i|f refere|
|000041e0| 6e 63 65 73 20 61 72 65 | 20 63 72 65 61 74 65 64 |nces are| created|
|000041f0| 20 69 6e 73 69 64 65 20 | 61 20 6c 6f 6f 70 20 74 | inside |a loop t|
|00004200| 68 61 74 20 6e 65 76 65 | 72 20 65 78 69 74 73 20 |hat neve|r exits |
|00004210| 62 61 63 6b 20 74 6f 20 | 50 72 6f 6c 6f 67 2e 0a |back to |Prolog..|
|00004220| 53 65 65 20 61 6c 73 6f | 20 50 4c 5f 6f 70 65 6e |See also| PL_open|
|00004230| 5f 66 6f 72 65 69 67 6e | 5f 66 72 61 6d 65 28 29 |_foreign|_frame()|
|00004240| 2c 20 50 4c 5f 63 6c 6f | 73 65 5f 66 6f 72 65 69 |, PL_clo|se_forei|
|00004250| 67 6e 5f 66 72 61 6d 65 | 28 29 20 61 6e 64 0a 50 |gn_frame|() and.P|
|00004260| 4c 5f 64 69 73 63 61 72 | 64 5f 66 6f 72 65 69 67 |L_discar|d_foreig|
|00004270| 6e 5f 66 72 61 6d 65 28 | 29 2e 0a 5c 65 6e 64 7b |n_frame(|)..\end{|
|00004280| 64 65 73 63 72 69 70 74 | 69 6f 6e 7d 0a 0a 0a 5c |descript|ion}...\|
|00004290| 73 75 62 73 75 62 73 65 | 63 74 69 6f 6e 7b 49 6e |subsubse|ction{In|
|000042a0| 74 65 72 61 63 74 69 6f | 6e 20 77 69 74 68 20 74 |teractio|n with t|
|000042b0| 68 65 20 67 61 72 62 61 | 67 65 20 63 6f 6c 6c 65 |he garba|ge colle|
|000042c0| 63 74 6f 72 20 61 6e 64 | 20 73 74 61 63 6b 2d 73 |ctor and| stack-s|
|000042d0| 68 69 66 74 65 72 7d 0a | 0a 50 72 6f 6c 6f 67 20 |hifter}.|.Prolog |
|000042e0| 69 6d 70 6c 65 6d 65 6e | 74 73 20 74 77 6f 20 6d |implemen|ts two m|
|000042f0| 65 63 68 61 6e 69 73 6d | 73 20 66 6f 72 20 61 76 |echanism|s for av|
|00004300| 6f 69 64 69 6e 67 20 73 | 74 61 63 6b 20 6f 76 65 |oiding s|tack ove|
|00004310| 72 66 6c 6f 77 3a 20 67 | 61 72 62 61 67 65 0a 63 |rflow: g|arbage.c|
|00004320| 6f 6c 6c 65 63 74 69 6f | 6e 20 61 6e 64 20 73 74 |ollectio|n and st|
|00004330| 61 63 6b 20 65 78 70 61 | 6e 73 69 6f 6e 2e 20 4f |ack expa|nsion. O|
|00004340| 6e 20 6d 61 63 68 69 6e | 65 73 20 74 68 61 74 20 |n machin|es that |
|00004350| 61 6c 6c 6f 77 20 66 6f | 72 20 69 74 2c 20 50 72 |allow fo|r it, Pr|
|00004360| 6f 6c 6f 67 0a 77 69 6c | 6c 20 75 73 65 20 76 69 |olog.wil|l use vi|
|00004370| 72 74 75 61 6c 20 6d 65 | 6d 6f 72 79 20 6d 61 6e |rtual me|mory man|
|00004380| 61 67 65 6d 65 6e 74 20 | 74 6f 20 64 65 74 65 63 |agement |to detec|
|00004390| 74 20 73 74 61 63 6b 20 | 6f 76 65 72 66 6c 6f 77 |t stack |overflow|
|000043a0| 20 61 6e 64 20 65 78 70 | 61 6e 64 0a 74 68 65 20 | and exp|and.the |
|000043b0| 72 75 6e 74 69 6d 65 20 | 73 74 61 63 6b 73 2e 20 |runtime |stacks. |
|000043c0| 4f 6e 20 6f 74 68 65 72 | 20 6d 61 63 68 69 6e 65 |On other| machine|
|000043d0| 73 20 50 72 6f 6c 6f 67 | 20 77 69 6c 6c 20 72 65 |s Prolog| will re|
|000043e0| 61 6c 6c 6f 63 61 74 65 | 20 74 68 65 20 73 74 61 |allocate| the sta|
|000043f0| 63 6b 73 0a 61 6e 64 20 | 75 70 64 61 74 65 20 61 |cks.and |update a|
|00004400| 6c 6c 20 70 6f 69 6e 74 | 65 72 73 20 74 6f 20 74 |ll point|ers to t|
|00004410| 68 65 6d 2e 20 54 6f 20 | 64 6f 20 73 6f 2c 20 50 |hem. To |do so, P|
|00004420| 72 6f 6c 6f 67 20 6e 65 | 65 64 73 20 74 6f 20 6b |rolog ne|eds to k|
|00004430| 6e 6f 77 20 77 68 69 63 | 68 0a 64 61 74 61 20 69 |now whic|h.data i|
|00004440| 73 20 72 65 66 65 72 65 | 6e 63 65 64 20 62 79 20 |s refere|nced by |
|00004450| 43 2d 63 6f 64 65 2e 20 | 41 73 20 61 6c 6c 20 50 |C-code. |As all P|
|00004460| 72 6f 6c 6f 67 20 64 61 | 74 61 20 6b 6e 6f 77 6e |rolog da|ta known|
|00004470| 20 62 79 20 43 20 69 73 | 0a 72 65 66 65 72 65 6e | by C is|.referen|
|00004480| 63 65 64 20 74 68 72 6f | 75 67 68 20 74 65 72 6d |ced thro|ugh term|
|00004490| 20 72 65 66 65 72 65 6e | 63 65 73 20 28 5c 63 74 | referen|ces (\ct|
|000044a0| 79 70 65 7b 74 65 72 6d | 5f 74 7d 29 2c 20 50 72 |ype{term|_t}), Pr|
|000044b0| 6f 6c 6f 67 20 68 61 73 | 20 61 6c 6c 0a 69 6e 66 |olog has| all.inf|
|000044c0| 6f 72 6d 61 74 69 6f 6e | 20 6e 65 63 65 73 73 61 |ormation| necessa|
|000044d0| 72 79 20 74 6f 20 70 65 | 72 66 6f 72 6d 20 69 74 |ry to pe|rform it|
|000044e0| 73 20 6d 65 6d 6f 72 79 | 20 6d 61 6e 61 67 65 6d |s memory| managem|
|000044f0| 65 6e 74 20 77 69 74 68 | 6f 75 74 20 0a 73 70 65 |ent with|out .spe|
|00004500| 63 69 61 6c 20 70 72 65 | 63 61 75 74 69 6f 6e 73 |cial pre|cautions|
|00004510| 20 66 72 6f 6d 20 74 68 | 65 20 43 2d 70 72 6f 67 | from th|e C-prog|
|00004520| 72 61 6d 6d 65 72 2e 0a | 0a 0a 5c 73 75 62 73 65 |rammer..|..\subse|
|00004530| 63 74 69 6f 6e 7b 4f 74 | 68 65 72 20 66 6f 72 65 |ction{Ot|her fore|
|00004540| 69 67 6e 20 69 6e 74 65 | 72 66 61 63 65 20 74 79 |ign inte|rface ty|
|00004550| 70 65 73 7d 0a 0a 5c 62 | 65 67 69 6e 7b 64 65 73 |pes}..\b|egin{des|
|00004560| 63 72 69 70 74 69 6f 6e | 7d 0a 20 20 20 20 5c 69 |cription|}. \i|
|00004570| 74 65 6d 5b 61 74 6f 6d | 5f 74 5d 0a 41 6e 20 61 |tem[atom|_t].An a|
|00004580| 74 6f 6d 20 69 6e 20 50 | 72 6f 6c 6f 67 73 20 69 |tom in P|rologs i|
|00004590| 6e 74 65 72 6e 61 6c 20 | 72 65 70 72 65 73 65 6e |nternal |represen|
|000045a0| 74 61 74 69 6f 6e 2e 20 | 20 41 74 6f 6d 73 20 61 |tation. | Atoms a|
|000045b0| 72 65 20 70 6f 69 6e 74 | 65 72 73 20 74 6f 20 61 |re point|ers to a|
|000045c0| 6e 0a 6f 70 61 71 75 65 | 20 73 74 72 75 63 74 75 |n.opaque| structu|
|000045d0| 72 65 2e 20 20 54 68 65 | 79 20 61 72 65 20 61 20 |re. The|y are a |
|000045e0| 75 6e 69 71 75 65 20 72 | 65 70 72 65 73 65 6e 74 |unique r|epresent|
|000045f0| 61 74 69 6f 6e 20 66 6f | 72 20 72 65 70 72 65 73 |ation fo|r repres|
|00004600| 65 6e 74 65 64 0a 74 65 | 78 74 2c 20 77 68 69 63 |ented.te|xt, whic|
|00004610| 68 20 69 6d 70 6c 69 65 | 73 20 74 68 61 74 20 61 |h implie|s that a|
|00004620| 74 6f 6d 20 24 41 24 20 | 72 65 70 72 65 73 65 6e |tom $A$ |represen|
|00004630| 74 73 20 74 68 65 20 73 | 61 6d 65 20 74 65 78 74 |ts the s|ame text|
|00004640| 20 61 73 0a 61 74 6f 6d | 20 24 42 24 20 69 66 2d | as.atom| $B$ if-|
|00004650| 61 6e 64 2d 6f 6e 6c 79 | 2d 69 66 20 24 41 24 20 |and-only|-if $A$ |
|00004660| 61 6e 64 20 24 42 24 20 | 61 72 65 20 74 68 65 20 |and $B$ |are the |
|00004670| 73 61 6d 65 20 70 6f 69 | 6e 74 65 72 2e 0a 0a 41 |same poi|nter...A|
|00004680| 74 6f 6d 73 20 61 72 65 | 20 74 68 65 20 63 65 6e |toms are| the cen|
|00004690| 74 72 61 6c 20 72 65 70 | 72 65 73 65 6e 74 61 74 |tral rep|resentat|
|000046a0| 69 6f 6e 20 66 6f 72 20 | 74 65 78 74 75 61 6c 20 |ion for |textual |
|000046b0| 63 6f 6e 73 74 61 6e 74 | 73 20 69 6e 20 50 72 6f |constant|s in Pro|
|000046c0| 6c 6f 67 0a 54 68 65 20 | 74 72 61 6e 73 66 6f 72 |log.The |transfor|
|000046d0| 6d 61 74 69 6f 6e 20 6f | 66 20 43 20 61 20 63 68 |mation o|f C a ch|
|000046e0| 61 72 61 63 74 65 72 20 | 73 74 72 69 6e 67 20 74 |aracter |string t|
|000046f0| 6f 20 61 6e 20 61 74 6f | 6d 20 69 6d 70 6c 69 65 |o an ato|m implie|
|00004700| 73 20 61 0a 68 61 73 68 | 2d 74 61 62 6c 65 20 6c |s a.hash|-table l|
|00004710| 6f 6f 6b 75 70 2e 20 20 | 49 66 20 74 68 65 20 73 |ookup. |If the s|
|00004720| 61 6d 65 20 61 74 6f 6d | 20 69 73 20 6e 65 65 64 |ame atom| is need|
|00004730| 65 64 20 6f 66 74 65 6e | 2c 20 69 74 20 69 73 20 |ed often|, it is |
|00004740| 61 64 76 69 73 65 64 0a | 74 6f 20 73 74 6f 72 65 |advised.|to store|
|00004750| 20 69 74 73 20 72 65 66 | 65 72 65 6e 63 65 20 69 | its ref|erence i|
|00004760| 6e 20 61 20 67 6c 6f 62 | 61 6c 20 76 61 72 69 61 |n a glob|al varia|
|00004770| 62 6c 65 20 74 6f 20 61 | 76 6f 69 64 20 72 65 70 |ble to a|void rep|
|00004780| 65 61 74 65 64 20 6c 6f | 6f 6b 75 70 2e 0a 20 20 |eated lo|okup.. |
|00004790| 20 20 5c 69 74 65 6d 5b | 66 75 6e 63 74 6f 72 5f | \item[|functor_|
|000047a0| 74 5d 0a 41 20 66 75 6e | 63 74 6f 72 20 69 73 20 |t].A fun|ctor is |
|000047b0| 74 68 65 20 69 6e 74 65 | 72 6e 61 6c 20 72 65 70 |the inte|rnal rep|
|000047c0| 72 65 73 65 6e 74 61 74 | 69 6f 6e 20 6f 66 20 61 |resentat|ion of a|
|000047d0| 20 6e 61 6d 65 2f 61 72 | 69 74 79 20 70 61 69 72 | name/ar|ity pair|
|000047e0| 2e 20 54 68 65 79 20 61 | 72 65 0a 75 73 65 64 20 |. They a|re.used |
|000047f0| 74 6f 20 66 69 6e 64 20 | 74 68 65 20 6e 61 6d 65 |to find |the name|
|00004800| 20 61 6e 64 20 61 72 69 | 74 79 20 6f 66 20 61 20 | and ari|ty of a |
|00004810| 63 6f 6d 70 6f 75 6e 64 | 20 74 65 72 6d 20 61 73 |compound| term as|
|00004820| 20 77 65 6c 6c 20 61 73 | 20 74 6f 0a 63 6f 6e 73 | well as| to.cons|
|00004830| 74 72 75 63 74 20 6e 65 | 77 20 63 6f 6d 70 6f 75 |truct ne|w compou|
|00004840| 6e 64 20 74 65 72 6d 73 | 2e 20 4c 69 6b 65 20 61 |nd terms|. Like a|
|00004850| 74 6f 6d 73 20 74 68 65 | 79 20 6c 69 76 65 20 66 |toms the|y live f|
|00004860| 6f 72 20 74 68 65 20 77 | 68 6f 6c 65 20 50 72 6f |or the w|hole Pro|
|00004870| 6c 6f 67 0a 73 65 73 73 | 69 6f 6e 20 61 6e 64 20 |log.sess|ion and |
|00004880| 61 72 65 20 75 6e 69 71 | 75 65 2e 0a 20 20 20 20 |are uniq|ue.. |
|00004890| 5c 69 74 65 6d 5b 70 72 | 65 64 69 63 61 74 65 5f |\item[pr|edicate_|
|000048a0| 74 5d 0a 48 61 6e 64 6c | 65 20 74 6f 20 61 20 50 |t].Handl|e to a P|
|000048b0| 72 6f 6c 6f 67 20 70 72 | 65 64 69 63 61 74 65 2e |rolog pr|edicate.|
|000048c0| 20 50 72 65 64 69 63 61 | 74 65 20 68 61 6e 64 6c | Predica|te handl|
|000048d0| 65 73 20 6c 69 76 65 20 | 66 6f 72 65 76 65 72 20 |es live |forever |
|000048e0| 28 61 6c 74 68 6f 75 67 | 68 0a 74 68 65 79 20 63 |(althoug|h.they c|
|000048f0| 61 6e 20 6c 6f 6f 73 65 | 20 74 68 65 69 72 20 64 |an loose| their d|
|00004900| 65 66 69 6e 69 74 69 6f | 6e 29 2e 0a 20 20 20 20 |efinitio|n).. |
|00004910| 5c 69 74 65 6d 5b 71 69 | 64 5f 74 5d 0a 51 75 65 |\item[qi|d_t].Que|
|00004920| 72 79 20 49 64 65 6e 74 | 69 66 69 65 72 2e 20 55 |ry Ident|ifier. U|
|00004930| 73 65 64 20 62 79 0a 50 | 4c 5f 6f 70 65 6e 5f 71 |sed by.P|L_open_q|
|00004940| 75 65 72 79 28 29 2f 50 | 4c 5f 6e 65 78 74 5f 73 |uery()/P|L_next_s|
|00004950| 6f 6c 75 74 69 6f 6e 28 | 29 2f 50 4c 5f 63 6c 6f |olution(|)/PL_clo|
|00004960| 73 65 5f 71 75 65 72 79 | 28 29 20 74 6f 20 68 61 |se_query|() to ha|
|00004970| 6e 64 6c 65 0a 62 61 63 | 6b 74 72 61 63 6b 69 6e |ndle.bac|ktrackin|
|00004980| 67 20 66 72 6f 6d 20 43 | 2e 0a 20 20 20 20 5c 69 |g from C|.. \i|
|00004990| 74 65 6d 5b 66 69 64 5f | 74 5d 0a 46 72 61 6d 65 |tem[fid_|t].Frame|
|000049a0| 20 49 64 65 6e 74 69 66 | 69 65 72 2e 20 55 73 65 | Identif|ier. Use|
|000049b0| 64 20 62 79 0a 50 4c 5f | 6f 70 65 6e 5f 66 6f 72 |d by.PL_|open_for|
|000049c0| 65 69 67 6e 5f 66 72 61 | 6d 65 28 29 2f 50 4c 5f |eign_fra|me()/PL_|
|000049d0| 63 6c 6f 73 65 5f 66 6f | 72 65 69 67 6e 5f 66 72 |close_fo|reign_fr|
|000049e0| 61 6d 65 28 29 2e 0a 20 | 20 20 20 5c 69 74 65 6d |ame().. | \item|
|000049f0| 5b 6d 6f 64 75 6c 65 5f | 74 5d 0a 41 20 6d 6f 64 |[module_|t].A mod|
|00004a00| 75 6c 65 20 69 73 20 61 | 20 75 6e 69 71 75 65 20 |ule is a| unique |
|00004a10| 68 61 6e 64 6c 65 20 74 | 6f 20 61 20 50 72 6f 6c |handle t|o a Prol|
|00004a20| 6f 67 20 6d 6f 64 75 6c | 65 2e 20 4d 6f 64 75 6c |og modul|e. Modul|
|00004a30| 65 73 20 61 72 65 20 75 | 73 65 64 20 6f 6e 6c 79 |es are u|sed only|
|00004a40| 0a 74 6f 20 63 61 6c 6c | 20 70 72 65 64 69 63 61 |.to call| predica|
|00004a50| 74 65 73 20 69 6e 20 61 | 20 73 70 65 63 69 66 69 |tes in a| specifi|
|00004a60| 63 20 6d 6f 64 75 6c 65 | 2e 0a 20 20 20 20 5c 69 |c module|.. \i|
|00004a70| 74 65 6d 5b 66 6f 72 65 | 69 67 6e 5f 74 5d 0a 52 |tem[fore|ign_t].R|
|00004a80| 65 74 75 72 6e 20 74 79 | 70 65 20 66 6f 72 20 61 |eturn ty|pe for a|
|00004a90| 20 43 2d 66 75 6e 63 74 | 69 6f 6e 20 69 6d 70 6c | C-funct|ion impl|
|00004aa0| 65 6d 65 6e 74 69 6e 67 | 20 61 20 50 72 6f 6c 6f |ementing| a Prolo|
|00004ab0| 67 20 70 72 65 64 69 63 | 61 74 65 2e 0a 20 20 20 |g predic|ate.. |
|00004ac0| 20 5c 69 74 65 6d 5b 63 | 6f 6e 74 72 6f 6c 5f 74 | \item[c|ontrol_t|
|00004ad0| 5d 0a 50 61 73 73 65 64 | 20 61 73 20 61 64 64 69 |].Passed| as addi|
|00004ae0| 74 69 6f 6e 61 6c 20 61 | 72 67 75 6d 65 6e 74 20 |tional a|rgument |
|00004af0| 74 6f 20 6e 6f 6e 2d 64 | 65 74 65 72 6d 69 6e 69 |to non-d|etermini|
|00004b00| 73 74 69 63 20 66 6f 72 | 65 69 67 6e 20 66 75 6e |stic for|eign fun|
|00004b10| 63 74 69 6f 6e 73 2e 0a | 53 65 65 20 50 4c 5f 72 |ctions..|See PL_r|
|00004b20| 65 74 72 79 2a 28 29 20 | 61 6e 64 20 50 4c 5f 66 |etry*() |and PL_f|
|00004b30| 6f 72 65 69 67 6e 5f 63 | 6f 6e 74 65 78 74 2a 28 |oreign_c|ontext*(|
|00004b40| 29 2e 0a 20 20 20 20 5c | 69 74 65 6d 5b 69 6e 73 |).. \|item[ins|
|00004b50| 74 61 6c 6c 5f 74 5d 0a | 54 79 70 65 20 66 6f 72 |tall_t].|Type for|
|00004b60| 20 74 68 65 20 69 6e 73 | 74 61 6c 6c 28 29 20 61 | the ins|tall() a|
|00004b70| 6e 64 20 75 6e 69 6e 73 | 74 61 6c 6c 28 29 20 66 |nd unins|tall() f|
|00004b80| 75 6e 63 74 69 6f 6e 73 | 20 6f 66 20 73 68 61 72 |unctions| of shar|
|00004b90| 65 64 0a 6f 72 20 64 79 | 6e 61 6d 69 63 20 6c 69 |ed.or dy|namic li|
|00004ba0| 6e 6b 20 6c 69 62 72 61 | 72 69 65 73 2e 20 20 53 |nk libra|ries. S|
|00004bb0| 65 65 20 73 65 63 72 65 | 66 7b 73 68 6c 69 62 7d |ee secre|f{shlib}|
|00004bc0| 2e 0a 5c 65 6e 64 7b 64 | 65 73 63 72 69 70 74 69 |..\end{d|escripti|
|00004bd0| 6f 6e 7d 0a 0a 5c 73 65 | 63 74 69 6f 6e 7b 54 68 |on}..\se|ction{Th|
|00004be0| 65 20 46 6f 72 65 69 67 | 6e 20 49 6e 63 6c 75 64 |e Foreig|n Includ|
|00004bf0| 65 20 46 69 6c 65 7d 0a | 0a 5c 73 75 62 73 65 63 |e File}.|.\subsec|
|00004c00| 74 69 6f 6e 7b 41 72 67 | 75 6d 65 6e 74 20 50 61 |tion{Arg|ument Pa|
|00004c10| 73 73 69 6e 67 20 61 6e | 64 20 43 6f 6e 74 72 6f |ssing an|d Contro|
|00004c20| 6c 7d 0a 0a 49 66 20 50 | 72 6f 6c 6f 67 20 65 6e |l}..If P|rolog en|
|00004c30| 63 6f 75 6e 74 65 72 73 | 20 61 20 66 6f 72 65 69 |counters| a forei|
|00004c40| 67 6e 20 70 72 65 64 69 | 63 61 74 65 20 61 74 20 |gn predi|cate at |
|00004c50| 72 75 6e 20 74 69 6d 65 | 20 69 74 20 77 69 6c 6c |run time| it will|
|00004c60| 20 63 61 6c 6c 20 61 0a | 66 75 6e 63 74 69 6f 6e | call a.|function|
|00004c70| 20 73 70 65 63 69 66 69 | 65 64 20 69 6e 20 74 68 | specifi|ed in th|
|00004c80| 65 20 70 72 65 64 69 63 | 61 74 65 20 64 65 66 69 |e predic|ate defi|
|00004c90| 6e 69 74 69 6f 6e 20 6f | 66 20 74 68 65 20 66 6f |nition o|f the fo|
|00004ca0| 72 65 69 67 6e 20 70 72 | 65 64 69 63 61 74 65 2e |reign pr|edicate.|
|00004cb0| 0a 54 68 65 20 61 72 67 | 75 6d 65 6e 74 73 20 24 |.The arg|uments $|
|00004cc0| 31 2c 20 5c 6c 64 6f 74 | 73 2c 20 3c 61 72 69 74 |1, \ldot|s, <arit|
|00004cd0| 79 3e 24 20 70 61 73 73 | 20 74 68 65 20 50 72 6f |y>$ pass| the Pro|
|00004ce0| 6c 6f 67 20 61 72 67 75 | 6d 65 6e 74 73 20 74 6f |log argu|ments to|
|00004cf0| 20 74 68 65 20 67 6f 61 | 6c 0a 61 73 20 50 72 6f | the goa|l.as Pro|
|00004d00| 6c 6f 67 20 74 65 72 6d | 73 2e 20 46 6f 72 65 69 |log term|s. Forei|
|00004d10| 67 6e 20 66 75 6e 63 74 | 69 6f 6e 73 20 73 68 6f |gn funct|ions sho|
|00004d20| 75 6c 64 20 62 65 20 64 | 65 63 6c 61 72 65 64 20 |uld be d|eclared |
|00004d30| 6f 66 20 74 79 70 65 0a | 5c 63 74 79 70 65 7b 66 |of type.|\ctype{f|
|00004d40| 6f 72 65 69 67 6e 5f 74 | 7d 2e 20 44 65 74 65 72 |oreign_t|}. Deter|
|00004d50| 6d 69 6e 69 73 74 69 63 | 20 66 6f 72 65 69 67 6e |ministic| foreign|
|00004d60| 20 66 75 6e 63 74 69 6f | 6e 73 20 68 61 76 65 20 | functio|ns have |
|00004d70| 74 77 6f 20 61 6c 74 65 | 72 6e 61 74 69 76 65 73 |two alte|rnatives|
|00004d80| 0a 74 6f 20 72 65 74 75 | 72 6e 20 63 6f 6e 74 72 |.to retu|rn contr|
|00004d90| 6f 6c 20 62 61 63 6b 20 | 74 6f 20 50 72 6f 6c 6f |ol back |to Prolo|
|00004da0| 67 3a 0a 0a 5c 62 65 67 | 69 6e 7b 64 65 73 63 72 |g:..\beg|in{descr|
|00004db0| 69 70 74 69 6f 6e 7d 0a | 20 20 20 20 5c 63 6d 61 |iption}.| \cma|
|00004dc0| 63 72 6f 7b 76 6f 69 64 | 7d 7b 50 4c 5f 73 75 63 |cro{void|}{PL_suc|
|00004dd0| 63 65 65 64 7d 7b 7d 0a | 53 75 63 63 65 65 64 20 |ceed}{}.|Succeed |
|00004de0| 64 65 74 65 72 6d 69 6e | 69 73 74 69 63 61 6c 6c |determin|isticall|
|00004df0| 79 2e 20 50 4c 5f 73 75 | 63 63 65 65 64 20 69 73 |y. PL_su|cceed is|
|00004e00| 20 64 65 66 69 6e 65 64 | 20 61 73 0a 5c 65 78 61 | defined| as.\exa|
|00004e10| 6d 7b 72 65 74 75 72 6e | 20 5c 63 6f 6e 73 74 7b |m{return| \const{|
|00004e20| 54 52 55 45 7d 7d 2e 0a | 20 20 20 20 5c 63 6d 61 |TRUE}}..| \cma|
|00004e30| 63 72 6f 7b 76 6f 69 64 | 7d 7b 50 4c 5f 66 61 69 |cro{void|}{PL_fai|
|00004e40| 6c 7d 7b 7d 0a 46 61 69 | 6c 20 61 6e 64 20 73 74 |l}{}.Fai|l and st|
|00004e50| 61 72 74 20 50 72 6f 6c | 6f 67 20 62 61 63 6b 74 |art Prol|og backt|
|00004e60| 72 61 63 6b 69 6e 67 2e | 20 20 50 4c 5f 66 61 69 |racking.| PL_fai|
|00004e70| 6c 20 69 73 20 64 65 66 | 69 6e 65 64 20 61 73 20 |l is def|ined as |
|00004e80| 5c 65 78 61 6d 7b 72 65 | 74 75 72 6e 0a 5c 63 6f |\exam{re|turn.\co|
|00004e90| 6e 73 74 7b 46 41 4c 53 | 45 7d 7d 2e 0a 5c 65 6e |nst{FALS|E}}..\en|
|00004ea0| 64 7b 64 65 73 63 72 69 | 70 74 69 6f 6e 7d 0a 0a |d{descri|ption}..|
|00004eb0| 5c 73 75 62 73 75 62 73 | 65 63 74 69 6f 6e 7b 4e |\subsubs|ection{N|
|00004ec0| 6f 6e 2d 64 65 74 65 72 | 6d 69 6e 69 73 74 69 63 |on-deter|ministic|
|00004ed0| 20 46 6f 72 65 69 67 6e | 20 50 72 65 64 69 63 61 | Foreign| Predica|
|00004ee0| 74 65 73 7d 0a 0a 42 79 | 20 64 65 66 61 75 6c 74 |tes}..By| default|
|00004ef0| 20 66 6f 72 65 69 67 6e | 20 70 72 65 64 69 63 61 | foreign| predica|
|00004f00| 74 65 73 20 61 72 65 20 | 64 65 74 65 72 6d 69 6e |tes are |determin|
|00004f10| 69 73 74 69 63 2e 20 55 | 73 69 6e 67 20 74 68 65 |istic. U|sing the|
|00004f20| 0a 5c 63 6f 6e 73 74 7b | 50 4c 5f 46 41 5f 4e 4f |.\const{|PL_FA_NO|
|00004f30| 4e 44 45 54 45 52 4d 49 | 4e 49 53 54 49 43 7d 20 |NDETERMI|NISTIC} |
|00004f40| 61 74 74 72 69 62 75 74 | 65 20 28 73 65 65 20 50 |attribut|e (see P|
|00004f50| 4c 5f 72 65 67 69 73 74 | 65 72 5f 66 6f 72 65 69 |L_regist|er_forei|
|00004f60| 67 6e 28 29 29 20 69 74 | 0a 69 73 20 70 6f 73 73 |gn()) it|.is poss|
|00004f70| 69 62 6c 65 20 74 6f 20 | 72 65 67 69 73 74 65 72 |ible to |register|
|00004f80| 20 61 20 70 72 65 64 69 | 63 61 74 65 20 61 73 20 | a predi|cate as |
|00004f90| 61 20 6e 6f 6e 2d 64 65 | 74 65 72 6d 69 6e 69 73 |a non-de|terminis|
|00004fa0| 74 69 63 20 70 72 65 64 | 69 63 61 74 65 2e 0a 57 |tic pred|icate..W|
|00004fb0| 72 69 74 69 6e 67 20 6e | 6f 6e 2d 64 65 74 65 72 |riting n|on-deter|
|00004fc0| 6d 69 6e 69 73 74 69 63 | 20 66 6f 72 65 69 67 6e |ministic| foreign|
|00004fd0| 20 70 72 65 64 69 63 61 | 74 65 73 20 69 73 20 73 | predica|tes is s|
|00004fe0| 6c 69 67 68 74 6c 79 20 | 6d 6f 72 65 0a 63 6f 6d |lightly |more.com|
|00004ff0| 70 6c 69 63 61 74 65 64 | 20 61 73 20 74 68 65 20 |plicated| as the |
|00005000| 66 6f 72 65 69 67 6e 20 | 66 75 6e 63 74 69 6f 6e |foreign |function|
|00005010| 20 6e 65 65 64 73 20 63 | 6f 6e 74 65 78 74 20 69 | needs c|ontext i|
|00005020| 6e 66 6f 72 6d 61 74 69 | 6f 6e 20 66 6f 72 0a 67 |nformati|on for.g|
|00005030| 65 6e 65 72 61 74 69 6e | 67 20 74 68 65 20 6e 65 |eneratin|g the ne|
|00005040| 78 74 20 73 6f 6c 75 74 | 69 6f 6e 2e 20 4e 6f 74 |xt solut|ion. Not|
|00005050| 65 20 74 68 61 74 20 74 | 68 65 20 73 61 6d 65 20 |e that t|he same |
|00005060| 66 6f 72 65 69 67 6e 20 | 66 75 6e 63 74 69 6f 6e |foreign |function|
|00005070| 20 73 68 6f 75 6c 64 0a | 62 65 20 70 72 65 70 61 | should.|be prepa|
|00005080| 72 65 64 20 74 6f 20 62 | 65 20 73 69 6d 75 6c 74 |red to b|e simult|
|00005090| 61 6e 65 6f 75 73 6c 79 | 20 61 63 74 69 76 65 20 |aneously| active |
|000050a0| 69 6e 20 6d 6f 72 65 20 | 74 68 61 6e 20 6f 6e 65 |in more |than one|
|000050b0| 20 67 6f 61 6c 2e 20 53 | 75 70 70 6f 73 65 0a 74 | goal. S|uppose.t|
|000050c0| 68 65 20 7b 6e 61 74 75 | 72 61 6c 5f 6e 75 6d 62 |he {natu|ral_numb|
|000050d0| 65 72 5f 62 65 6c 6f 77 | 5f 6e 7d 2f 32 20 69 73 |er_below|_n}/2 is|
|000050e0| 20 61 20 6e 6f 6e 2d 64 | 65 74 65 72 6d 69 6e 69 | a non-d|etermini|
|000050f0| 73 74 69 63 20 66 6f 72 | 65 69 67 6e 20 70 72 65 |stic for|eign pre|
|00005100| 64 69 63 61 74 65 2c 0a | 62 61 63 6b 74 72 61 63 |dicate,.|backtrac|
|00005110| 6b 69 6e 67 20 6f 76 65 | 72 20 61 6c 6c 20 6e 61 |king ove|r all na|
|00005120| 74 75 72 61 6c 20 6e 75 | 6d 62 65 72 73 20 6c 6f |tural nu|mbers lo|
|00005130| 77 65 72 20 74 68 61 6e | 20 74 68 65 20 66 69 72 |wer than| the fir|
|00005140| 73 74 20 61 72 67 75 6d | 65 6e 74 2e 20 4e 6f 77 |st argum|ent. Now|
|00005150| 0a 63 6f 6e 73 69 64 65 | 72 20 74 68 65 20 66 6f |.conside|r the fo|
|00005160| 6c 6c 6f 77 69 6e 67 20 | 70 72 65 64 69 63 61 74 |llowing |predicat|
|00005170| 65 3a 0a 0a 5c 62 65 67 | 69 6e 7b 63 6f 64 65 7d |e:..\beg|in{code}|
|00005180| 0a 71 75 6f 74 69 65 6e | 74 5f 62 65 6c 6f 77 5f |.quotien|t_below_|
|00005190| 6e 28 51 2c 20 4e 29 20 | 3a 2d 0a 20 20 20 20 20 |n(Q, N) |:-. |
|000051a0| 20 20 20 6e 61 74 75 72 | 61 6c 5f 6e 75 6d 62 65 | natur|al_numbe|
|000051b0| 72 5f 62 65 6c 6f 77 5f | 6e 28 4e 2c 20 4e 31 29 |r_below_|n(N, N1)|
|000051c0| 2c 0a 20 20 20 20 20 20 | 20 20 6e 61 74 75 72 61 |,. | natura|
|000051d0| 6c 5f 6e 75 6d 62 65 72 | 5f 62 65 6c 6f 77 5f 6e |l_number|_below_n|
|000051e0| 28 4e 2c 20 4e 32 29 2c | 0a 20 20 20 20 20 20 20 |(N, N2),|. |
|000051f0| 20 51 20 3d 3a 3d 20 4e | 31 20 2f 20 4e 32 2c 20 | Q =:= N|1 / N2, |
|00005200| 21 2e 0a 5c 65 6e 64 7b | 63 6f 64 65 7d 0a 0a 49 |!..\end{|code}..I|
|00005210| 6e 20 74 68 69 73 20 70 | 72 65 64 69 63 61 74 65 |n this p|redicate|
|00005220| 20 74 68 65 20 66 75 6e | 63 74 69 6f 6e 20 7b 6e | the fun|ction {n|
|00005230| 61 74 75 72 61 6c 5f 6e | 75 6d 62 65 72 5f 62 65 |atural_n|umber_be|
|00005240| 6c 6f 77 5f 6e 7d 2f 32 | 20 73 69 6d 75 6c 74 61 |low_n}/2| simulta|
|00005250| 6e 65 6f 75 73 6c 79 0a | 67 65 6e 65 72 61 74 65 |neously.|generate|
|00005260| 73 20 73 6f 6c 75 74 69 | 6f 6e 73 20 66 6f 72 20 |s soluti|ons for |
|00005270| 62 6f 74 68 20 69 74 73 | 20 69 6e 76 6f 63 61 74 |both its| invocat|
|00005280| 69 6f 6e 73 2e 0a 0a 4e | 6f 6e 2d 64 65 74 65 72 |ions...N|on-deter|
|00005290| 6d 69 6e 69 73 74 69 63 | 20 66 6f 72 65 69 67 6e |ministic| foreign|
|000052a0| 20 66 75 6e 63 74 69 6f | 6e 73 20 73 68 6f 75 6c | functio|ns shoul|
|000052b0| 64 20 62 65 20 70 72 65 | 70 61 72 65 64 20 74 6f |d be pre|pared to|
|000052c0| 20 68 61 6e 64 6c 65 20 | 74 68 72 65 65 0a 64 69 | handle |three.di|
|000052d0| 66 66 65 72 65 6e 74 20 | 63 61 6c 6c 73 20 66 72 |fferent |calls fr|
|000052e0| 6f 6d 20 50 72 6f 6c 6f | 67 3a 0a 0a 5c 62 65 67 |om Prolo|g:..\beg|
|000052f0| 69 6e 7b 69 74 65 6d 6c | 69 73 74 7d 0a 20 20 20 |in{iteml|ist}. |
|00005300| 20 5c 69 74 65 6d 20 5b | 49 6e 69 74 69 61 6c 20 | \item [|Initial |
|00005310| 63 61 6c 6c 20 28 5c 63 | 6f 6e 73 74 7b 50 4c 5f |call (\c|onst{PL_|
|00005320| 46 49 52 53 54 5f 43 41 | 4c 4c 7d 29 5d 0a 50 72 |FIRST_CA|LL})].Pr|
|00005330| 6f 6c 6f 67 20 68 61 73 | 20 6a 75 73 74 20 63 72 |olog has| just cr|
|00005340| 65 61 74 65 64 20 61 20 | 66 72 61 6d 65 20 66 6f |eated a |frame fo|
|00005350| 72 20 74 68 65 20 66 6f | 72 65 69 67 6e 20 66 75 |r the fo|reign fu|
|00005360| 6e 63 74 69 6f 6e 20 61 | 6e 64 20 61 73 6b 73 20 |nction a|nd asks |
|00005370| 69 74 20 74 6f 0a 70 72 | 6f 64 75 63 65 20 74 68 |it to.pr|oduce th|
|00005380| 65 20 66 69 72 73 74 20 | 61 6e 73 77 65 72 2e 0a |e first |answer..|
|00005390| 20 20 20 20 5c 69 74 65 | 6d 20 5b 52 65 64 6f 20 | \ite|m [Redo |
|000053a0| 63 61 6c 6c 20 28 5c 63 | 6f 6e 73 74 7b 50 4c 5f |call (\c|onst{PL_|
|000053b0| 52 45 44 4f 7d 29 5d 0a | 54 68 65 20 70 72 65 76 |REDO})].|The prev|
|000053c0| 69 6f 75 73 20 69 6e 76 | 6f 63 61 74 69 6f 6e 20 |ious inv|ocation |
|000053d0| 6f 66 20 74 68 65 20 66 | 6f 72 65 69 67 6e 20 66 |of the f|oreign f|
|000053e0| 75 6e 63 74 69 6f 6e 20 | 61 73 73 6f 63 69 61 74 |unction |associat|
|000053f0| 65 64 20 77 69 74 68 20 | 74 68 65 0a 63 75 72 72 |ed with |the.curr|
|00005400| 65 6e 74 20 67 6f 61 6c | 20 69 6e 64 69 63 61 74 |ent goal| indicat|
|00005410| 65 64 20 69 74 20 77 61 | 73 20 70 6f 73 73 69 62 |ed it wa|s possib|
|00005420| 6c 65 20 74 6f 20 62 61 | 63 6b 74 72 61 63 6b 2e |le to ba|cktrack.|
|00005430| 20 20 54 68 65 20 66 6f | 72 65 69 67 6e 0a 66 75 | The fo|reign.fu|
|00005440| 6e 63 74 69 6f 6e 20 73 | 68 6f 75 6c 64 20 70 72 |nction s|hould pr|
|00005450| 6f 64 75 63 65 20 74 68 | 65 20 6e 65 78 74 20 73 |oduce th|e next s|
|00005460| 6f 6c 75 74 69 6f 6e 2e | 0a 20 20 20 20 5c 69 74 |olution.|. \it|
|00005470| 65 6d 20 5b 54 65 72 6d | 69 6e 61 74 65 20 63 61 |em [Term|inate ca|
|00005480| 6c 6c 20 28 5c 63 6f 6e | 73 74 7b 50 4c 5f 43 55 |ll (\con|st{PL_CU|
|00005490| 54 54 45 44 7d 29 5d 0a | 54 68 65 20 63 68 6f 69 |TTED})].|The choi|
|000054a0| 63 65 20 70 6f 69 6e 74 | 20 6c 65 66 74 20 62 79 |ce point| left by|
|000054b0| 20 74 68 65 20 66 6f 72 | 65 69 67 6e 20 66 75 6e | the for|eign fun|
|000054c0| 63 74 69 6f 6e 20 68 61 | 73 20 62 65 65 6e 20 64 |ction ha|s been d|
|000054d0| 65 73 74 72 6f 79 65 64 | 20 62 79 0a 61 20 63 75 |estroyed| by.a cu|
|000054e0| 74 2e 20 20 54 68 65 20 | 66 6f 72 65 69 67 6e 20 |t. The |foreign |
|000054f0| 66 75 6e 63 74 69 6f 6e | 20 69 73 20 67 69 76 65 |function| is give|
|00005500| 6e 20 74 68 65 20 6f 70 | 70 6f 72 74 75 6e 69 74 |n the op|portunit|
|00005510| 79 20 74 6f 20 63 6c 65 | 61 6e 20 74 68 65 0a 65 |y to cle|an the.e|
|00005520| 6e 76 69 72 6f 6e 6d 65 | 6e 74 2e 0a 5c 65 6e 64 |nvironme|nt..\end|
|00005530| 7b 69 74 65 6d 6c 69 73 | 74 7d 0a 0a 42 6f 74 68 |{itemlis|t}..Both|
|00005540| 20 74 68 65 20 63 6f 6e | 74 65 78 74 20 69 6e 66 | the con|text inf|
|00005550| 6f 72 6d 61 74 69 6f 6e | 20 61 6e 64 20 74 68 65 |ormation| and the|
|00005560| 20 74 79 70 65 20 6f 66 | 20 63 61 6c 6c 20 69 73 | type of| call is|
|00005570| 20 70 72 6f 76 69 64 65 | 64 20 62 79 20 61 6e 0a | provide|d by an.|
|00005580| 61 72 67 75 6d 65 6e 74 | 20 6f 66 20 74 79 70 65 |argument| of type|
|00005590| 20 5c 63 74 79 70 65 7b | 63 6f 6e 74 72 6f 6c 5f | \ctype{|control_|
|000055a0| 74 7d 20 61 70 70 65 6e | 64 65 64 20 74 6f 20 74 |t} appen|ded to t|
|000055b0| 68 65 20 61 72 67 75 6d | 65 6e 74 20 6c 69 73 74 |he argum|ent list|
|000055c0| 20 66 6f 72 0a 64 65 74 | 65 72 6d 69 6e 69 73 74 | for.det|erminist|
|000055d0| 69 63 20 66 6f 72 65 69 | 67 6e 20 66 75 6e 63 74 |ic forei|gn funct|
|000055e0| 69 6f 6e 73 2e 20 20 54 | 68 65 20 6d 61 63 72 6f |ions. T|he macro|
|000055f0| 20 50 4c 5f 66 6f 72 65 | 69 67 6e 5f 63 6f 6e 74 | PL_fore|ign_cont|
|00005600| 72 6f 6c 28 29 0a 65 78 | 74 72 61 63 74 73 20 74 |rol().ex|tracts t|
|00005610| 68 65 20 74 79 70 65 20 | 6f 66 20 63 61 6c 6c 20 |he type |of call |
|00005620| 66 72 6f 6d 20 74 68 65 | 20 63 6f 6e 74 72 6f 6c |from the| control|
|00005630| 20 61 72 67 75 6d 65 6e | 74 2e 20 20 54 68 65 20 | argumen|t. The |
|00005640| 66 6f 72 65 69 67 6e 0a | 66 75 6e 63 74 69 6f 6e |foreign.|function|
|00005650| 20 63 61 6e 20 70 61 73 | 73 20 61 20 63 6f 6e 74 | can pas|s a cont|
|00005660| 65 78 74 20 68 61 6e 64 | 6c 65 20 75 73 69 6e 67 |ext hand|le using|
|00005670| 20 74 68 65 20 7b 5c 74 | 74 20 50 4c 5f 72 65 74 | the {\t|t PL_ret|
|00005680| 72 79 2a 28 29 7d 20 6d | 61 63 72 6f 73 20 61 6e |ry*()} m|acros an|
|00005690| 64 0a 65 78 74 72 61 63 | 74 20 74 68 65 20 68 61 |d.extrac|t the ha|
|000056a0| 6e 64 6c 65 20 66 72 6f | 6d 20 74 68 65 20 65 78 |ndle fro|m the ex|
|000056b0| 74 72 61 20 61 72 67 75 | 6d 65 6e 74 20 75 73 69 |tra argu|ment usi|
|000056c0| 6e 67 20 74 68 65 0a 7b | 5c 74 74 20 50 4c 5f 66 |ng the.{|\tt PL_f|
|000056d0| 6f 72 65 69 67 6e 5f 63 | 6f 6e 74 65 78 74 2a 28 |oreign_c|ontext*(|
|000056e0| 29 7d 20 6d 61 63 72 6f | 2e 0a 0a 5c 62 65 67 69 |)} macro|...\begi|
|000056f0| 6e 7b 64 65 73 63 72 69 | 70 74 69 6f 6e 7d 0a 20 |n{descri|ption}. |
|00005700| 20 20 20 5c 63 6d 61 63 | 72 6f 7b 76 6f 69 64 7d | \cmac|ro{void}|
|00005710| 7b 50 4c 5f 72 65 74 72 | 79 7d 7b 6c 6f 6e 67 7d |{PL_retr|y}{long}|
|00005720| 0a 54 68 65 20 66 6f 72 | 65 69 67 6e 20 66 75 6e |.The for|eign fun|
|00005730| 63 74 69 6f 6e 20 73 75 | 63 63 65 65 64 73 20 77 |ction su|cceeds w|
|00005740| 68 69 6c 65 20 6c 65 61 | 76 69 6e 67 20 61 20 63 |hile lea|ving a c|
|00005750| 68 6f 69 63 65 20 70 6f | 69 6e 74 2e 20 4f 6e 0a |hoice po|int. On.|
|00005760| 62 61 63 6b 74 72 61 63 | 6b 69 6e 67 20 6f 76 65 |backtrac|king ove|
|00005770| 72 20 74 68 69 73 20 67 | 6f 61 6c 20 74 68 65 20 |r this g|oal the |
|00005780| 66 6f 72 65 69 67 6e 20 | 66 75 6e 63 74 69 6f 6e |foreign |function|
|00005790| 20 77 69 6c 6c 20 62 65 | 20 63 61 6c 6c 65 64 20 | will be| called |
|000057a0| 61 67 61 69 6e 2c 0a 62 | 75 74 20 74 68 65 20 63 |again,.b|ut the c|
|000057b0| 6f 6e 74 72 6f 6c 20 61 | 72 67 75 6d 65 6e 74 20 |ontrol a|rgument |
|000057c0| 6e 6f 77 20 69 6e 64 69 | 63 61 74 65 73 20 69 74 |now indi|cates it|
|000057d0| 20 69 73 20 61 20 60 52 | 65 64 6f 27 20 63 61 6c | is a `R|edo' cal|
|000057e0| 6c 20 61 6e 64 20 74 68 | 65 0a 6d 61 63 72 6f 20 |l and th|e.macro |
|000057f0| 50 4c 5f 66 6f 72 65 69 | 67 6e 5f 63 6f 6e 74 65 |PL_forei|gn_conte|
|00005800| 78 74 28 29 20 77 69 6c | 6c 20 72 65 74 75 72 6e |xt() wil|l return|
|00005810| 20 74 68 65 20 68 61 6e | 64 6c 65 20 70 61 73 73 | the han|dle pass|
|00005820| 65 64 20 76 69 61 0a 50 | 4c 5f 72 65 74 72 79 28 |ed via.P|L_retry(|
|00005830| 29 2e 20 54 68 69 73 20 | 68 61 6e 64 6c 65 20 69 |). This |handle i|
|00005840| 73 20 61 20 33 30 20 62 | 69 74 73 20 73 69 67 6e |s a 30 b|its sign|
|00005850| 65 64 20 76 61 6c 75 65 | 20 28 74 77 6f 20 62 69 |ed value| (two bi|
|00005860| 74 73 20 61 72 65 20 75 | 73 65 64 0a 66 6f 72 20 |ts are u|sed.for |
|00005870| 73 74 61 74 75 73 20 69 | 6e 64 69 63 61 74 69 6f |status i|ndicatio|
|00005880| 6e 29 2e 0a 0a 20 20 20 | 20 5c 63 6d 61 63 72 6f |n)... | \cmacro|
|00005890| 7b 76 6f 69 64 7d 7b 50 | 4c 5f 72 65 74 72 79 5f |{void}{P|L_retry_|
|000058a0| 61 64 64 72 65 73 73 7d | 7b 76 6f 69 64 20 2a 7d |address}|{void *}|
|000058b0| 0a 41 73 20 50 4c 5f 72 | 65 74 72 79 28 29 2c 20 |.As PL_r|etry(), |
|000058c0| 62 75 74 20 65 6e 73 75 | 72 65 73 20 61 6e 20 61 |but ensu|res an a|
|000058d0| 64 64 72 65 73 73 20 61 | 73 20 72 65 74 75 72 6e |ddress a|s return|
|000058e0| 65 64 20 62 79 20 6d 61 | 6c 6c 6f 63 28 29 20 69 |ed by ma|lloc() i|
|000058f0| 73 0a 63 6f 72 72 65 63 | 74 6c 79 20 72 65 63 6f |s.correc|tly reco|
|00005900| 76 65 72 65 64 20 62 79 | 20 50 4c 5f 66 6f 72 65 |vered by| PL_fore|
|00005910| 69 67 6e 5f 63 6f 6e 74 | 65 78 74 5f 61 64 64 72 |ign_cont|ext_addr|
|00005920| 65 73 73 28 29 2e 0a 0a | 20 20 20 20 5c 63 6d 61 |ess()...| \cma|
|00005930| 63 72 6f 7b 69 6e 74 7d | 7b 50 4c 5f 66 6f 72 65 |cro{int}|{PL_fore|
|00005940| 69 67 6e 5f 63 6f 6e 74 | 72 6f 6c 7d 7b 63 6f 6e |ign_cont|rol}{con|
|00005950| 74 72 6f 6c 5f 74 7d 0a | 45 78 74 72 61 63 74 73 |trol_t}.|Extracts|
|00005960| 20 74 68 65 20 74 79 70 | 65 20 6f 66 20 63 61 6c | the typ|e of cal|
|00005970| 6c 20 66 72 6f 6d 20 74 | 68 65 20 63 6f 6e 74 72 |l from t|he contr|
|00005980| 6f 6c 20 61 72 67 75 6d | 65 6e 74 2e 20 20 54 68 |ol argum|ent. Th|
|00005990| 65 20 72 65 74 75 72 6e | 20 76 61 6c 75 65 73 0a |e return| values.|
|000059a0| 61 72 65 20 64 65 73 63 | 72 69 62 65 64 20 61 62 |are desc|ribed ab|
|000059b0| 6f 76 65 2e 20 20 4e 6f | 74 65 20 74 68 61 74 20 |ove. No|te that |
|000059c0| 74 68 65 20 66 75 6e 63 | 74 69 6f 6e 20 73 68 6f |the func|tion sho|
|000059d0| 75 6c 64 20 62 65 20 70 | 72 65 70 61 72 65 64 20 |uld be p|repared |
|000059e0| 74 6f 0a 68 61 6e 64 6c | 65 20 74 68 65 20 5c 63 |to.handl|e the \c|
|000059f0| 6f 6e 73 74 7b 50 4c 5f | 43 55 54 54 45 44 7d 20 |onst{PL_|CUTTED} |
|00005a00| 63 61 73 65 20 61 6e 64 | 20 73 68 6f 75 6c 64 20 |case and| should |
|00005a10| 62 65 20 61 77 61 72 65 | 20 74 68 61 74 20 74 68 |be aware| that th|
|00005a20| 65 20 6f 74 68 65 72 0a | 61 72 67 75 6d 65 6e 74 |e other.|argument|
|00005a30| 73 20 61 72 65 20 6e 6f | 74 20 76 61 6c 69 64 20 |s are no|t valid |
|00005a40| 69 6e 20 74 68 69 73 20 | 63 61 73 65 2e 0a 0a 20 |in this |case... |
|00005a50| 20 20 20 5c 63 6d 61 63 | 72 6f 7b 6c 6f 6e 67 7d | \cmac|ro{long}|
|00005a60| 7b 50 4c 5f 66 6f 72 65 | 69 67 6e 5f 63 6f 6e 74 |{PL_fore|ign_cont|
|00005a70| 65 78 74 7d 7b 63 6f 6e | 74 72 6f 6c 5f 74 7d 0a |ext}{con|trol_t}.|
|00005a80| 45 78 74 72 61 63 74 73 | 20 74 68 65 20 63 6f 6e |Extracts| the con|
|00005a90| 74 65 78 74 20 66 72 6f | 6d 20 74 68 65 20 63 6f |text fro|m the co|
|00005aa0| 6e 74 65 78 74 20 61 72 | 67 75 6d 65 6e 74 2e 20 |ntext ar|gument. |
|00005ab0| 20 49 6e 20 74 68 65 20 | 63 61 6c 6c 20 74 79 70 | In the |call typ|
|00005ac0| 65 20 69 73 0a 5c 63 6f | 6e 73 74 7b 50 4c 5f 46 |e is.\co|nst{PL_F|
|00005ad0| 49 52 53 54 5f 43 41 4c | 4c 7d 20 74 68 65 20 63 |IRST_CAL|L} the c|
|00005ae0| 6f 6e 74 65 78 74 20 76 | 61 6c 75 65 20 69 73 20 |ontext v|alue is |
|00005af0| 30 4c 2e 20 20 4f 74 68 | 65 72 77 69 73 65 20 69 |0L. Oth|erwise i|
|00005b00| 74 20 69 73 20 74 68 65 | 20 76 61 6c 75 65 0a 72 |t is the| value.r|
|00005b10| 65 74 75 72 6e 65 64 20 | 62 79 20 74 68 65 20 6c |eturned |by the l|
|00005b20| 61 73 74 20 50 4c 5f 72 | 65 74 72 79 28 29 20 61 |ast PL_r|etry() a|
|00005b30| 73 73 6f 63 69 61 74 65 | 64 20 77 69 74 68 20 74 |ssociate|d with t|
|00005b40| 68 69 73 20 67 6f 61 6c | 20 28 62 6f 74 68 20 69 |his goal| (both i|
|00005b50| 66 20 74 68 65 0a 63 61 | 6c 6c 20 74 79 70 65 20 |f the.ca|ll type |
|00005b60| 69 73 20 5c 63 6f 6e 73 | 74 7b 50 4c 5f 52 45 44 |is \cons|t{PL_RED|
|00005b70| 4f 7d 20 61 73 20 5c 63 | 6f 6e 73 74 7b 50 4c 5f |O} as \c|onst{PL_|
|00005b80| 43 55 54 54 45 44 7d 29 | 2e 0a 0a 20 20 20 20 5c |CUTTED})|... \|
|00005b90| 63 6d 61 63 72 6f 7b 76 | 6f 69 64 20 2a 7d 7b 50 |cmacro{v|oid *}{P|
|00005ba0| 4c 5f 66 6f 72 65 69 67 | 6e 5f 63 6f 6e 74 65 78 |L_foreig|n_contex|
|00005bb0| 74 5f 61 64 64 72 65 73 | 73 7d 7b 63 6f 6e 74 72 |t_addres|s}{contr|
|00005bc0| 6f 6c 5f 74 7d 0a 45 78 | 74 72 61 63 74 73 20 61 |ol_t}.Ex|tracts a|
|00005bd0| 6e 20 61 64 64 72 65 73 | 73 20 61 73 20 70 61 73 |n addres|s as pas|
|00005be0| 73 65 64 20 69 6e 20 62 | 79 20 50 4c 5f 72 65 74 |sed in b|y PL_ret|
|00005bf0| 72 79 5f 61 64 64 72 65 | 73 73 28 29 2e 0a 5c 65 |ry_addre|ss()..\e|
|00005c00| 6e 64 7b 64 65 73 63 72 | 69 70 74 69 6f 6e 7d 0a |nd{descr|iption}.|
|00005c10| 0a 4e 6f 74 65 3a 20 49 | 66 20 61 20 6e 6f 6e 2d |.Note: I|f a non-|
|00005c20| 64 65 74 65 72 6d 69 6e | 69 73 74 69 63 20 66 6f |determin|istic fo|
|00005c30| 72 65 69 67 6e 20 66 75 | 6e 63 74 69 6f 6e 20 72 |reign fu|nction r|
|00005c40| 65 74 75 72 6e 73 20 75 | 73 69 6e 67 20 50 4c 5f |eturns u|sing PL_|
|00005c50| 73 75 63 63 65 65 64 0a | 6f 72 20 50 4c 5f 66 61 |succeed.|or PL_fa|
|00005c60| 69 6c 2c 20 50 72 6f 6c | 6f 67 20 61 73 73 75 6d |il, Prol|og assum|
|00005c70| 65 73 20 74 68 65 20 66 | 6f 72 65 69 67 6e 20 66 |es the f|oreign f|
|00005c80| 75 6e 63 74 69 6f 6e 20 | 68 61 73 20 63 6c 65 61 |unction |has clea|
|00005c90| 6e 65 64 20 69 74 73 0a | 65 6e 76 69 72 6f 6e 6d |ned its.|environm|
|00005ca0| 65 6e 74 2e 20 7b 5c 62 | 66 20 4e 6f 7d 20 63 61 |ent. {\b|f No} ca|
|00005cb0| 6c 6c 20 77 69 74 68 20 | 63 6f 6e 74 72 6f 6c 20 |ll with |control |
|00005cc0| 61 72 67 75 6d 65 6e 74 | 20 5c 63 6f 6e 73 74 7b |argument| \const{|
|00005cd0| 50 4c 5f 43 55 54 54 45 | 44 7d 20 77 69 6c 6c 0a |PL_CUTTE|D} will.|
|00005ce0| 66 6f 6c 6c 6f 77 2e 0a | 0a 54 68 65 20 63 6f 64 |follow..|.The cod|
|00005cf0| 65 20 6f 66 20 5c 66 69 | 67 72 65 66 7b 6e 6f 6e |e of \fi|gref{non|
|00005d00| 64 65 74 65 72 6d 66 7d | 20 73 68 6f 77 73 20 61 |determf}| shows a|
|00005d10| 20 73 6b 65 6c 65 74 6f | 6e 20 66 6f 72 20 61 0a | skeleto|n for a.|
|00005d20| 6e 6f 6e 2d 64 65 74 65 | 72 6d 69 6e 69 73 74 69 |non-dete|rministi|
|00005d30| 63 20 66 6f 72 65 69 67 | 6e 20 70 72 65 64 69 63 |c foreig|n predic|
|00005d40| 61 74 65 20 64 65 66 69 | 6e 69 74 69 6f 6e 2e 0a |ate defi|nition..|
|00005d50| 0a 5c 62 65 67 69 6e 7b | 66 69 67 75 72 65 7d 0a |.\begin{|figure}.|
|00005d60| 5c 62 65 67 69 6e 7b 63 | 6f 64 65 7d 0a 74 79 70 |\begin{c|ode}.typ|
|00005d70| 65 64 65 66 20 73 74 72 | 75 63 74 20 20 20 20 20 |edef str|uct |
|00005d80| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 2f 2a 20 | | /* |
|00005d90| 64 65 66 69 6e 65 20 61 | 20 63 6f 6e 74 65 78 74 |define a| context|
|00005da0| 20 73 74 72 75 63 74 75 | 72 65 20 2a 2f 0a 7b 20 | structu|re */.{ |
|00005db0| 2e 2e 2e 0a 7d 20 63 6f | 6e 74 65 78 74 3b 0a 0a |....} co|ntext;..|
|00005dc0| 66 6f 72 65 69 67 6e 5f | 74 0a 6d 79 5f 66 75 6e |foreign_|t.my_fun|
|00005dd0| 63 74 69 6f 6e 28 74 65 | 72 6d 5f 74 20 61 30 2c |ction(te|rm_t a0,|
|00005de0| 20 74 65 72 6d 5f 74 20 | 61 31 2c 20 66 6f 72 65 | term_t |a1, fore|
|00005df0| 69 67 6e 5f 74 20 68 61 | 6e 64 6c 65 29 0a 7b 20 |ign_t ha|ndle).{ |
|00005e00| 73 74 72 75 63 74 20 63 | 6f 6e 74 65 78 74 20 2a |struct c|ontext *|
|00005e10| 20 63 74 78 74 3b 0a 0a | 20 20 73 77 69 74 63 68 | ctxt;..| switch|
|00005e20| 28 20 50 4c 5f 66 6f 72 | 65 69 67 6e 5f 63 6f 6e |( PL_for|eign_con|
|00005e30| 74 72 6f 6c 28 68 61 6e | 64 6c 65 29 20 29 0a 20 |trol(han|dle) ). |
|00005e40| 20 7b 20 63 61 73 65 20 | 50 4c 5f 46 49 52 53 54 | { case |PL_FIRST|
|00005e50| 5f 43 41 4c 4c 3a 0a 20 | 20 20 20 20 20 20 20 63 |_CALL:. | c|
|00005e60| 74 78 74 20 3d 20 6d 61 | 6c 6c 6f 63 28 73 69 7a |txt = ma|lloc(siz|
|00005e70| 65 6f 66 28 73 74 72 75 | 63 74 20 63 6f 6e 74 65 |eof(stru|ct conte|
|00005e80| 78 74 29 29 3b 0a 20 20 | 20 20 20 20 20 20 2e 2e |xt));. | ..|
|00005e90| 2e 0a 20 20 20 20 20 20 | 20 20 50 4c 5f 72 65 74 |.. | PL_ret|
|00005ea0| 72 79 5f 61 64 64 72 65 | 73 73 28 63 74 78 74 29 |ry_addre|ss(ctxt)|
|00005eb0| 3b 0a 20 20 20 20 63 61 | 73 65 20 50 4c 5f 52 45 |;. ca|se PL_RE|
|00005ec0| 44 4f 3a 0a 20 20 20 20 | 20 20 20 20 63 74 78 74 |DO:. | ctxt|
|00005ed0| 20 3d 20 50 4c 5f 66 6f | 72 65 69 67 6e 5f 63 6f | = PL_fo|reign_co|
|00005ee0| 6e 74 65 78 74 5f 61 64 | 64 72 65 73 73 28 68 61 |ntext_ad|dress(ha|
|00005ef0| 6e 64 6c 65 29 3b 0a 20 | 20 20 20 20 20 20 20 2e |ndle);. | .|
|00005f00| 2e 2e 0a 20 20 20 20 20 | 20 20 20 50 4c 5f 72 65 |... | PL_re|
|00005f10| 74 72 79 5f 61 64 64 72 | 65 73 73 28 63 74 78 74 |try_addr|ess(ctxt|
|00005f20| 29 3b 0a 20 20 20 20 63 | 61 73 65 20 50 4c 5f 43 |);. c|ase PL_C|
|00005f30| 55 54 54 45 44 3a 0a 20 | 20 20 20 20 20 20 20 66 |UTTED:. | f|
|00005f40| 72 65 65 28 63 74 78 74 | 29 3b 0a 20 20 20 20 20 |ree(ctxt|);. |
|00005f50| 20 20 20 50 4c 5f 73 75 | 63 63 65 65 64 3b 0a 20 | PL_su|cceed;. |
|00005f60| 20 7d 0a 7d 0a 5c 65 6e | 64 7b 63 6f 64 65 7d 0a | }.}.\en|d{code}.|
|00005f70| 20 20 20 20 5c 63 61 70 | 74 69 6f 6e 7b 53 6b 65 | \cap|tion{Ske|
|00005f80| 6c 65 74 6f 6e 20 66 6f | 72 20 6e 6f 6e 2d 64 65 |leton fo|r non-de|
|00005f90| 74 65 72 6d 69 6e 69 73 | 74 69 63 20 66 6f 72 65 |terminis|tic fore|
|00005fa0| 69 67 6e 20 66 75 6e 63 | 74 69 6f 6e 73 7d 0a 20 |ign func|tions}. |
|00005fb0| 20 20 20 5c 6c 61 62 65 | 6c 7b 66 69 67 3a 6e 6f | \labe|l{fig:no|
|00005fc0| 6e 64 65 74 65 72 6d 66 | 7d 0a 5c 65 6e 64 7b 66 |ndetermf|}.\end{f|
|00005fd0| 69 67 75 72 65 7d 0a 0a | 0a 5c 73 75 62 73 65 63 |igure}..|.\subsec|
|00005fe0| 74 69 6f 6e 7b 41 74 6f | 6d 73 20 61 6e 64 20 66 |tion{Ato|ms and f|
|00005ff0| 75 6e 63 74 6f 72 73 7d | 0a 0a 54 68 65 20 66 6f |unctors}|..The fo|
|00006000| 6c 6c 6f 77 69 6e 67 20 | 66 75 6e 63 74 69 6f 6e |llowing |function|
|00006010| 73 20 70 72 6f 76 69 64 | 65 20 66 6f 72 20 63 6f |s provid|e for co|
|00006020| 6d 6d 75 6e 69 63 61 74 | 69 6f 6e 20 75 73 69 6e |mmunicat|ion usin|
|00006030| 67 20 61 74 6f 6d 73 20 | 61 6e 64 0a 66 75 6e 63 |g atoms |and.func|
|00006040| 74 6f 72 73 2e 0a 0a 5c | 62 65 67 69 6e 7b 64 65 |tors...\|begin{de|
|00006050| 73 63 72 69 70 74 69 6f | 6e 7d 0a 5c 63 66 75 6e |scriptio|n}.\cfun|
|00006060| 63 74 69 6f 6e 7b 61 74 | 6f 6d 5f 74 7d 7b 50 4c |ction{at|om_t}{PL|
|00006070| 5f 6e 65 77 5f 61 74 6f | 6d 7d 7b 63 6f 6e 73 74 |_new_ato|m}{const|
|00006080| 20 63 68 61 72 20 2a 7d | 0a 52 65 74 75 72 6e 20 | char *}|.Return |
|00006090| 61 6e 20 61 74 6f 6d 20 | 68 61 6e 64 6c 65 20 66 |an atom |handle f|
|000060a0| 6f 72 20 74 68 65 20 67 | 69 76 65 6e 20 43 2d 73 |or the g|iven C-s|
|000060b0| 74 72 69 6e 67 2e 20 20 | 54 68 69 73 20 66 75 6e |tring. |This fun|
|000060c0| 63 74 69 6f 6e 20 61 6c | 77 61 79 73 0a 73 75 63 |ction al|ways.suc|
|000060d0| 63 65 65 64 73 2e 20 20 | 54 68 65 20 72 65 74 75 |ceeds. |The retu|
|000060e0| 72 6e 65 64 20 68 61 6e | 64 6c 65 20 69 73 20 76 |rned han|dle is v|
|000060f0| 61 6c 69 64 20 66 6f 72 | 20 74 68 65 20 65 6e 74 |alid for| the ent|
|00006100| 69 72 65 20 73 65 73 73 | 69 6f 6e 2e 0a 5c 63 66 |ire sess|ion..\cf|
|00006110| 75 6e 63 74 69 6f 6e 7b | 63 6f 6e 73 74 20 63 68 |unction{|const ch|
|00006120| 61 72 20 2a 7d 7b 50 4c | 5f 61 74 6f 6d 5f 63 68 |ar *}{PL|_atom_ch|
|00006130| 61 72 73 7d 7b 61 74 6f | 6d 5f 74 20 61 74 6f 6d |ars}{ato|m_t atom|
|00006140| 7d 0a 52 65 74 75 72 6e | 20 61 20 43 2d 73 74 72 |}.Return| a C-str|
|00006150| 69 6e 67 20 66 6f 72 20 | 74 68 65 20 74 65 78 74 |ing for |the text|
|00006160| 20 72 65 70 72 65 73 65 | 6e 74 65 64 20 62 79 20 | represe|nted by |
|00006170| 74 68 65 20 67 69 76 65 | 6e 20 61 74 6f 6d 2e 20 |the give|n atom. |
|00006180| 20 54 68 65 0a 72 65 74 | 75 72 6e 65 64 20 74 65 | The.ret|urned te|
|00006190| 78 74 20 77 69 6c 6c 20 | 6e 6f 74 20 62 65 20 63 |xt will |not be c|
|000061a0| 68 61 6e 67 65 64 20 62 | 79 20 50 72 6f 6c 6f 67 |hanged b|y Prolog|
|000061b0| 2e 20 20 49 74 20 69 73 | 20 6e 6f 74 20 61 6c 6c |. It is| not all|
|000061c0| 6f 77 65 64 20 74 6f 0a | 6d 6f 64 69 66 79 20 74 |owed to.|modify t|
|000061d0| 68 65 20 63 6f 6e 74 65 | 6e 74 73 2c 20 6e 6f 74 |he conte|nts, not|
|000061e0| 20 65 76 65 6e 20 60 74 | 65 6d 70 6f 72 61 72 79 | even `t|emporary|
|000061f0| 27 20 61 73 20 74 68 65 | 20 73 74 72 69 6e 67 20 |' as the| string |
|00006200| 6d 61 79 20 72 65 73 69 | 64 65 0a 69 6e 20 72 65 |may resi|de.in re|
|00006210| 61 64 2d 6f 6e 6c 79 20 | 6d 65 6d 6f 72 79 2e 0a |ad-only |memory..|
|00006220| 5c 63 66 75 6e 63 74 69 | 6f 6e 7b 66 75 6e 63 74 |\cfuncti|on{funct|
|00006230| 6f 72 5f 74 7d 7b 50 4c | 5f 6e 65 77 5f 66 75 6e |or_t}{PL|_new_fun|
|00006240| 63 74 6f 72 7d 7b 61 74 | 6f 6d 5f 74 20 6e 61 6d |ctor}{at|om_t nam|
|00006250| 65 2c 20 69 6e 74 20 61 | 72 69 74 79 7d 0a 52 65 |e, int a|rity}.Re|
|00006260| 74 75 72 6e 73 20 61 20 | 7b 5c 65 6d 20 66 75 6e |turns a |{\em fun|
|00006270| 63 74 6f 72 20 69 64 65 | 6e 74 69 66 69 65 72 7d |ctor ide|ntifier}|
|00006280| 2c 20 61 20 68 61 6e 64 | 6c 65 20 66 6f 72 20 74 |, a hand|le for t|
|00006290| 68 65 20 6e 61 6d 65 2f | 61 72 69 74 79 0a 70 61 |he name/|arity.pa|
|000062a0| 69 72 2e 20 20 54 68 65 | 20 72 65 74 75 72 6e 65 |ir. The| returne|
|000062b0| 64 20 68 61 6e 64 6c 65 | 20 69 73 20 76 61 6c 69 |d handle| is vali|
|000062c0| 64 20 66 6f 72 20 74 68 | 65 20 65 6e 74 69 72 65 |d for th|e entire|
|000062d0| 20 50 72 6f 6c 6f 67 20 | 73 65 73 73 69 6f 6e 2e | Prolog |session.|
|000062e0| 0a 5c 63 66 75 6e 63 74 | 69 6f 6e 7b 61 74 6f 6d |.\cfunct|ion{atom|
|000062f0| 5f 74 7d 7b 50 4c 5f 66 | 75 6e 63 74 6f 72 5f 6e |_t}{PL_f|unctor_n|
|00006300| 61 6d 65 7d 7b 66 75 6e | 63 74 6f 72 5f 74 20 66 |ame}{fun|ctor_t f|
|00006310| 7d 0a 52 65 74 75 72 6e | 20 61 6e 20 61 74 6f 6d |}.Return| an atom|
|00006320| 20 72 65 70 72 65 73 65 | 6e 74 69 6e 67 20 74 68 | represe|nting th|
|00006330| 65 20 6e 61 6d 65 20 6f | 66 20 74 68 65 20 67 69 |e name o|f the gi|
|00006340| 76 65 6e 20 66 75 6e 63 | 74 6f 72 2e 0a 5c 63 66 |ven func|tor..\cf|
|00006350| 75 6e 63 74 69 6f 6e 7b | 69 6e 74 7d 7b 50 4c 5f |unction{|int}{PL_|
|00006360| 66 75 6e 63 74 6f 72 5f | 61 72 69 74 79 7d 7b 66 |functor_|arity}{f|
|00006370| 75 6e 63 74 6f 72 5f 74 | 20 66 7d 0a 52 65 74 75 |unctor_t| f}.Retu|
|00006380| 72 6e 20 74 68 65 20 61 | 72 69 74 79 20 6f 66 20 |rn the a|rity of |
|00006390| 74 68 65 20 67 69 76 65 | 6e 20 66 75 6e 63 74 6f |the give|n functo|
|000063a0| 72 2e 0a 5c 65 6e 64 7b | 64 65 73 63 72 69 70 74 |r..\end{|descript|
|000063b0| 69 6f 6e 7d 0a 0a 0a 5c | 73 75 62 73 65 63 74 69 |ion}...\|subsecti|
|000063c0| 6f 6e 7b 41 6e 61 6c 79 | 73 69 6e 67 20 54 65 72 |on{Analy|sing Ter|
|000063d0| 6d 73 20 76 69 61 20 74 | 68 65 20 46 6f 72 65 69 |ms via t|he Forei|
|000063e0| 67 6e 20 49 6e 74 65 72 | 66 61 63 65 7d 0a 0a 45 |gn Inter|face}..E|
|000063f0| 61 63 68 20 61 72 67 75 | 6d 65 6e 74 20 6f 66 20 |ach argu|ment of |
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.